convert most sprintf() to snprintf().
This commit is contained in:
parent
03c86659de
commit
a164d00c0b
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: scan.c,v 1.32 2016/03/12 02:26:40 dholland Exp $ */
|
||||
/* $NetBSD: scan.c,v 1.33 2019/10/04 21:33:57 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1992 Carnegie Mellon University
|
||||
|
@ -279,7 +279,7 @@ getrelease(char *release)
|
|||
frelease = release = estrdup(DEFRELEASE);
|
||||
listTL = NULL;
|
||||
|
||||
(void) sprintf(buf, FILERELEASES, collname);
|
||||
snprintf(buf, sizeof buf, FILERELEASES, collname);
|
||||
f = fopen(buf, "r");
|
||||
if (f != NULL) {
|
||||
rewound = TRUE;
|
||||
|
@ -350,7 +350,7 @@ makescanlists(void)
|
|||
char *saveprefix = prefix;
|
||||
int count = 0;
|
||||
|
||||
(void) sprintf(buf, FILERELEASES, collname);
|
||||
snprintf(buf, sizeof buf, FILERELEASES, collname);
|
||||
f = fopen(buf, "r");
|
||||
if (f != NULL) {
|
||||
while ((p = fgets(buf, sizeof(buf), f)) != NULL) {
|
||||
|
@ -451,7 +451,7 @@ doscan(char *listfile)
|
|||
rsymT = NULL;
|
||||
if (listfile == NULL)
|
||||
listfile = FILELISTDEF;
|
||||
(void) sprintf(buf, FILELIST, collname, listfile);
|
||||
snprintf(buf, sizeof buf, FILELIST, collname, listfile);
|
||||
readlistfile(buf); /* get contents of list file */
|
||||
(void) Tprocess(upgT, listone, NULL); /* build list of files
|
||||
* specified */
|
||||
|
@ -577,7 +577,7 @@ expTinsert(char *p, TREE ** t, int flags, char *exec)
|
|||
newt = Tinsert(t, speclist[i], TRUE);
|
||||
newt->Tflags |= flags;
|
||||
if (exec) {
|
||||
(void) sprintf(buf, exec, speclist[i]);
|
||||
snprintf(buf, sizeof buf, exec, speclist[i]);
|
||||
(void) Tinsert(&newt->Texec, buf, FALSE);
|
||||
}
|
||||
free(speclist[i]);
|
||||
|
@ -724,7 +724,7 @@ listdir(char *name, int always)
|
|||
if (strcmp(dentry->d_name, "..") == 0)
|
||||
continue;
|
||||
if (*newname) {
|
||||
(void)snprintf(filename, sizeof(filename), "%s/%s",
|
||||
snprintf(filename, sizeof(filename), "%s/%s",
|
||||
newname, dentry->d_name);
|
||||
} else {
|
||||
(void)strncpy(filename, dentry->d_name,
|
||||
|
@ -829,7 +829,7 @@ getscanfile(char *scanfile)
|
|||
|
||||
if (scanfile == NULL)
|
||||
scanfile = FILESCANDEF;
|
||||
(void) sprintf(buf, FILESCAN, collname, scanfile);
|
||||
snprintf(buf, sizeof buf, FILESCAN, collname, scanfile);
|
||||
if (stat(buf, &sbuf) < 0)
|
||||
return (FALSE);
|
||||
if ((f = fopen(buf, "r")) == NULL)
|
||||
|
@ -930,8 +930,8 @@ chkscanfile(char *scanfile)
|
|||
|
||||
if (scanfile == NULL)
|
||||
scanfile = FILESCANDEF;
|
||||
(void) sprintf(fname, FILESCAN, collname, scanfile);
|
||||
(void) sprintf(tname, "%s.temp", fname);
|
||||
snprintf(fname, sizeof fname, FILESCAN, collname, scanfile);
|
||||
snprintf(tname, sizeof tname, "%s.temp", fname);
|
||||
if (NULL == (f = fopen(tname, "w")))
|
||||
goaway("Can't test scan file temp %s for %s", tname, collname);
|
||||
else {
|
||||
|
@ -949,8 +949,8 @@ makescanfile(char *scanfile)
|
|||
|
||||
if (scanfile == NULL)
|
||||
scanfile = FILESCANDEF;
|
||||
(void) sprintf(fname, FILESCAN, collname, scanfile);
|
||||
(void) sprintf(tname, "%s.temp", fname);
|
||||
snprintf(fname, sizeof fname, FILESCAN, collname, scanfile);
|
||||
snprintf(tname, sizeof tname, "%s.temp", fname);
|
||||
scanF = fopen(tname, "w");
|
||||
if (scanF == NULL)
|
||||
goto out;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: supcmain.c,v 1.34 2017/05/04 16:26:10 sevan Exp $ */
|
||||
/* $NetBSD: supcmain.c,v 1.35 2019/10/04 21:33:57 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1992 Carnegie Mellon University
|
||||
|
@ -718,7 +718,7 @@ init(int argc, char **argv)
|
|||
c->Cnotify = estrdup(username);
|
||||
}
|
||||
if (c->Cbase == NULL) {
|
||||
(void) sprintf(buf, FILEBASEDEFAULT, c->Cname);
|
||||
snprintf(buf, sizeof buf, FILEBASEDEFAULT, c->Cname);
|
||||
c->Cbase = estrdup(buf);
|
||||
}
|
||||
}
|
||||
|
@ -737,7 +737,7 @@ init(int argc, char **argv)
|
|||
else if (sysflag)
|
||||
p = "system software";
|
||||
else
|
||||
(void) sprintf(p = buf, "file %s", supfname);
|
||||
snprintf(p = buf, sizeof buf, "file %s", supfname);
|
||||
if (!silent)
|
||||
loginfo("SUP %d.%d (%s) for %s at %s", PROTOVERSION, PGMVERSION,
|
||||
scmversion, p, fmttime(timenow));
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: supcmisc.c,v 1.23 2013/03/08 20:56:44 christos Exp $ */
|
||||
/* $NetBSD: supcmisc.c,v 1.24 2019/10/04 21:33:57 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1992 Carnegie Mellon University
|
||||
|
@ -85,15 +85,15 @@ prtime(void)
|
|||
time_t twhen;
|
||||
|
||||
if ((thisC->Cflags & CFURELSUF) && thisC->Crelease)
|
||||
(void) sprintf(relsufix, ".%s", thisC->Crelease);
|
||||
snprintf(relsufix, sizeof relsufix, ".%s", thisC->Crelease);
|
||||
else
|
||||
relsufix[0] = '\0';
|
||||
if (chdir(thisC->Cbase) < 0)
|
||||
logerr("Can't change to base directory %s for collection %s",
|
||||
thisC->Cbase, thisC->Cname);
|
||||
twhen = getwhen(thisC->Cname, relsufix);
|
||||
(void) strcpy(buf, ctime(&twhen));
|
||||
buf[strlen(buf) - 1] = '\0';
|
||||
strncpy(buf, ctime(&twhen), sizeof(buf) - 1);
|
||||
buf[sizeof(buf) - 1] = '\0';
|
||||
loginfo("Last update occurred at %s for collection %s%s",
|
||||
buf, thisC->Cname, relsufix);
|
||||
}
|
||||
|
@ -282,9 +282,10 @@ notify(int f, const char *fmt, ...)
|
|||
va_start(ap, fmt);
|
||||
|
||||
if ((thisC->Cflags & CFURELSUF) && thisC->Crelease)
|
||||
(void) sprintf(collrelname, "%s-%s", collname, thisC->Crelease);
|
||||
snprintf(collrelname, sizeof collrelname, "%s-%s", collname,
|
||||
thisC->Crelease);
|
||||
else
|
||||
(void) strcpy(collrelname, collname);
|
||||
strcpy(collrelname, collname);
|
||||
|
||||
if (fmt == NULL) {
|
||||
if (noteF && noteF != stdout && (!silent || thisC->Cnogood)) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: supcname.c,v 1.7 2009/10/17 20:46:03 christos Exp $ */
|
||||
/* $NetBSD: supcname.c,v 1.8 2019/10/04 21:33:57 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1992 Carnegie Mellon University
|
||||
|
@ -77,7 +77,7 @@ getnams(void)
|
|||
for (c = firstC; c && c->Chtree != NULL; c = c->Cnext);
|
||||
if (c == NULL)
|
||||
return;
|
||||
(void) sprintf(buf, FILEHOSTS, DEFDIR);
|
||||
snprintf(buf, sizeof buf, FILEHOSTS, DEFDIR);
|
||||
f = fopen(buf, "r");
|
||||
if (f == NULL)
|
||||
logquit(1, "Can't open %s", buf);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: supcparse.c,v 1.16 2013/04/09 16:39:20 christos Exp $ */
|
||||
/* $NetBSD: supcparse.c,v 1.17 2019/10/04 21:33:57 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1992 Carnegie Mellon University
|
||||
|
@ -242,7 +242,7 @@ getwhen(char *collection, char *relsuffix)
|
|||
FILE *fp;
|
||||
time_t tstamp;
|
||||
|
||||
(void) sprintf(buf, FILEWHEN, collection, relsuffix);
|
||||
snprintf(buf, sizeof buf, FILEWHEN, collection, relsuffix);
|
||||
|
||||
if ((fp = fopen(buf, "r")) == NULL)
|
||||
return 0;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: supfilesrv.c,v 1.52 2019/02/03 03:19:31 mrg Exp $ */
|
||||
/* $NetBSD: supfilesrv.c,v 1.53 2019/10/04 21:33:57 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1992 Carnegie Mellon University
|
||||
|
@ -889,7 +889,7 @@ srvsetup(void)
|
|||
|
||||
/* check crosspatch host access file */
|
||||
cryptkey = NULL;
|
||||
(void) sprintf(buf, FILEXPATCH, xuser);
|
||||
snprintf(buf, sizeof buf, FILEXPATCH, xuser);
|
||||
|
||||
/* Turn off link following */
|
||||
if (link_nofollow(1) != -1) {
|
||||
|
@ -955,7 +955,7 @@ srvsetup(void)
|
|||
release = estrdup(DEFRELEASE);
|
||||
if (basedir == NULL || *basedir == '\0') {
|
||||
basedir = NULL;
|
||||
(void) sprintf(filename, FILEDIRS, DEFDIR);
|
||||
snprintf(filename, sizeof filename, FILEDIRS, DEFDIR);
|
||||
f = fopen(filename, "r");
|
||||
if (f) {
|
||||
while ((p = fgets(buf, STRINGLENGTH, f)) != NULL) {
|
||||
|
@ -974,14 +974,14 @@ srvsetup(void)
|
|||
(void) fclose(f);
|
||||
}
|
||||
if (basedir == NULL) {
|
||||
(void) sprintf(buf, FILEBASEDEFAULT, collname);
|
||||
snprintf(buf, sizeof buf, FILEBASEDEFAULT, collname);
|
||||
basedir = estrdup(buf);
|
||||
}
|
||||
}
|
||||
if (chdir(basedir) < 0)
|
||||
goaway("Can't chdir to base directory %s (%s)", basedir,
|
||||
strerror(errno));
|
||||
(void) sprintf(filename, FILEPREFIX, collname);
|
||||
snprintf(filename, sizeof filename, FILEPREFIX, collname);
|
||||
f = fopen(filename, "r");
|
||||
if (f) {
|
||||
while ((p = fgets(buf, STRINGLENGTH, f)) != NULL) {
|
||||
|
@ -1038,7 +1038,7 @@ srvsetup(void)
|
|||
char *h;
|
||||
if ((h = tl->TLhost) == NULL)
|
||||
h = FILEHOSTDEF;
|
||||
(void) sprintf(buf, FILEHOST, collname, h);
|
||||
snprintf(buf, sizeof buf, FILEHOST, collname, h);
|
||||
f = fopen(buf, "r");
|
||||
if (f) {
|
||||
int hostok = FALSE;
|
||||
|
@ -1073,7 +1073,7 @@ srvsetup(void)
|
|||
}
|
||||
}
|
||||
/* try to lock collection */
|
||||
(void) sprintf(buf, FILELOCK, collname);
|
||||
snprintf(buf, sizeof buf, FILELOCK, collname);
|
||||
#ifdef LOCK_SH
|
||||
x = open(buf, O_RDONLY, 0);
|
||||
if (x >= 0) {
|
||||
|
@ -1107,7 +1107,7 @@ docrypt(void)
|
|||
struct stat sbuf;
|
||||
|
||||
if (!xpatch) {
|
||||
(void) sprintf(buf, FILECRYPT, collname);
|
||||
snprintf(buf, sizeof buf, FILECRYPT, collname);
|
||||
|
||||
/* Turn off link following */
|
||||
if (link_nofollow(1) != -1) {
|
||||
|
@ -1393,7 +1393,8 @@ send_one(TREE * t, void *v __unused)
|
|||
av[ac++] = "-q";
|
||||
av[ac++] = "-p";
|
||||
if (rcs_branch != NULL) {
|
||||
sprintf(rcs_release, "-r%s",
|
||||
snprintf(rcs_release,
|
||||
sizeof rcs_release, "-r%s",
|
||||
rcs_branch);
|
||||
av[ac++] = rcs_release;
|
||||
}
|
||||
|
@ -1561,7 +1562,7 @@ srvfinishup(time_t starttime)
|
|||
logerr("%s: NULL collection in svrfinishup", remotehost());
|
||||
return;
|
||||
}
|
||||
(void) sprintf(lognam, FILELOGFILE, collname);
|
||||
snprintf(lognam, sizeof lognam, FILELOGFILE, collname);
|
||||
if ((logfd = open(lognam, O_APPEND | O_WRONLY, 0644)) < 0)
|
||||
return; /* can not open file up...error */
|
||||
finishtime = time(NULL);
|
||||
|
@ -1703,9 +1704,9 @@ changeuid(char *namep, char *passwordp, int fileuid, int filegid)
|
|||
if (namep == NULL) {
|
||||
pwd = getpwuid(fileuid);
|
||||
if (pwd == NULL) {
|
||||
(void) sprintf(errbuf, "Reason: Unknown user id %d",
|
||||
fileuid);
|
||||
return (errbuf);
|
||||
snprintf(errbuf, sizeof errbuf,
|
||||
"Reason: Unknown user id %d", fileuid);
|
||||
return errbuf;
|
||||
}
|
||||
grp = getgrgid(filegid);
|
||||
if (grp)
|
||||
|
@ -1730,9 +1731,9 @@ changeuid(char *namep, char *passwordp, int fileuid, int filegid)
|
|||
}
|
||||
pwd = getpwnam(nbuf);
|
||||
if (pwd == NULL) {
|
||||
(void) sprintf(errbuf, "Reason: Unknown user %s",
|
||||
nbuf);
|
||||
return (errbuf);
|
||||
snprintf(errbuf, sizeof errbuf,
|
||||
"Reason: Unknown user %s", nbuf);
|
||||
return errbuf;
|
||||
}
|
||||
if (strcmp(nbuf, DEFUSER) == 0)
|
||||
pswdp = NULL;
|
||||
|
@ -1744,11 +1745,11 @@ changeuid(char *namep, char *passwordp, int fileuid, int filegid)
|
|||
setpag(); /* set a pag */
|
||||
if (ka_UserAuthenticate(pwd->pw_name, "", 0,
|
||||
pswdp, 1, &reason)) {
|
||||
(void) sprintf(errbuf, "AFS authentication failed, %s",
|
||||
reason);
|
||||
snprintf(errbuf, sizeof errbuf,
|
||||
"AFS authentication failed, %s", reason);
|
||||
logerr("Attempt by %s; %s",
|
||||
nbuf, errbuf);
|
||||
return (errbuf);
|
||||
return errbuf;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -1789,7 +1790,7 @@ changeuid(char *namep, char *passwordp, int fileuid, int filegid)
|
|||
break;
|
||||
#if CMUCS
|
||||
case ACCESS_CODE_INSECUREPWD:
|
||||
(void) sprintf(errbuf, "Reason: %s", p);
|
||||
snprintf(errbuf, sizeof errbuf, "Reason: %s", p);
|
||||
p = errbuf;
|
||||
break;
|
||||
case ACCESS_CODE_DENIED:
|
||||
|
@ -1830,7 +1831,8 @@ changeuid(char *namep, char *passwordp, int fileuid, int filegid)
|
|||
break;
|
||||
#endif /* CMUCS */
|
||||
default:
|
||||
(void) sprintf(p = errbuf, "Reason: Status %d", status);
|
||||
snprintf(errbuf, sizeof errbuf, "Reason: Status %d", status);
|
||||
p = errbuf;
|
||||
break;
|
||||
}
|
||||
if (status != ACCESS_CODE_OK) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: supscan.c,v 1.24 2017/05/04 16:26:10 sevan Exp $ */
|
||||
/* $NetBSD: supscan.c,v 1.25 2019/10/04 21:33:57 mrg Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1992 Carnegie Mellon University
|
||||
|
@ -284,7 +284,7 @@ init(int argc, char **argv)
|
|||
argv++;
|
||||
}
|
||||
if (!fflag) {
|
||||
(void) sprintf(fbuf, FILEDIRS, DEFDIR);
|
||||
snprintf(fbuf, sizeof fbuf, FILEDIRS, DEFDIR);
|
||||
filename = fbuf;
|
||||
}
|
||||
if (sflag) {
|
||||
|
@ -292,7 +292,7 @@ init(int argc, char **argv)
|
|||
usage();
|
||||
firstC = NULL;
|
||||
c = &firstC;
|
||||
(void) sprintf(buf, FILEHOSTS, DEFDIR);
|
||||
snprintf(buf, sizeof buf, FILEHOSTS, DEFDIR);
|
||||
if ((f = fopen(buf, "r")) == NULL)
|
||||
quit(1, "supscan: Unable to open %s\n", buf);
|
||||
while ((p = fgets(buf, STRINGLENGTH, f)) != NULL) {
|
||||
|
@ -370,7 +370,7 @@ getscancoll(char *filename, char *collname, char *basedir)
|
|||
(void) fclose(f);
|
||||
}
|
||||
if (basedir == NULL) {
|
||||
(void) sprintf(buf, FILEBASEDEFAULT, collname);
|
||||
snprintf(buf, sizeof buf, FILEBASEDEFAULT, collname);
|
||||
basedir = estrdup(buf);
|
||||
}
|
||||
}
|
||||
|
@ -380,7 +380,7 @@ getscancoll(char *filename, char *collname, char *basedir)
|
|||
return (NULL);
|
||||
}
|
||||
prefix = NULL;
|
||||
(void) sprintf(buf, FILEPREFIX, collname);
|
||||
snprintf(buf, sizeof buf, FILEPREFIX, collname);
|
||||
if ((f = fopen(buf, "r")) != NULL) {
|
||||
while ((p = fgets(buf, STRINGLENGTH, f)) != NULL) {
|
||||
q = strchr(p, '\n');
|
||||
|
|
Loading…
Reference in New Issue