Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/sup/source convert most sprintf() to snprintf().



details:   https://anonhg.NetBSD.org/src/rev/a96cfbca72a7
branches:  trunk
changeset: 460030:a96cfbca72a7
user:      mrg <mrg%NetBSD.org@localhost>
date:      Fri Oct 04 21:33:57 2019 +0000

description:
convert most sprintf() to snprintf().

diffstat:

 usr.sbin/sup/source/scan.c       |  22 ++++++++++----------
 usr.sbin/sup/source/supcmain.c   |   6 ++--
 usr.sbin/sup/source/supcmisc.c   |  13 ++++++-----
 usr.sbin/sup/source/supcname.c   |   4 +-
 usr.sbin/sup/source/supcparse.c  |   4 +-
 usr.sbin/sup/source/supfilesrv.c |  44 ++++++++++++++++++++-------------------
 usr.sbin/sup/source/supscan.c    |  10 ++++----
 7 files changed, 53 insertions(+), 50 deletions(-)

diffs (truncated from 384 to 300 lines):

diff -r 93dd9bf8e47f -r a96cfbca72a7 usr.sbin/sup/source/scan.c
--- a/usr.sbin/sup/source/scan.c        Fri Oct 04 16:27:00 2019 +0000
+++ b/usr.sbin/sup/source/scan.c        Fri Oct 04 21:33:57 2019 +0000
@@ -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 @@
                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 @@
        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 @@
        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 @@
                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 @@
                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 @@
 
        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 @@
 
        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 @@
 
        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;
diff -r 93dd9bf8e47f -r a96cfbca72a7 usr.sbin/sup/source/supcmain.c
--- a/usr.sbin/sup/source/supcmain.c    Fri Oct 04 16:27:00 2019 +0000
+++ b/usr.sbin/sup/source/supcmain.c    Fri Oct 04 21:33:57 2019 +0000
@@ -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 @@
                                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 @@
        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));
diff -r 93dd9bf8e47f -r a96cfbca72a7 usr.sbin/sup/source/supcmisc.c
--- a/usr.sbin/sup/source/supcmisc.c    Fri Oct 04 16:27:00 2019 +0000
+++ b/usr.sbin/sup/source/supcmisc.c    Fri Oct 04 21:33:57 2019 +0000
@@ -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 @@
        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 @@
        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)) {
diff -r 93dd9bf8e47f -r a96cfbca72a7 usr.sbin/sup/source/supcname.c
--- a/usr.sbin/sup/source/supcname.c    Fri Oct 04 16:27:00 2019 +0000
+++ b/usr.sbin/sup/source/supcname.c    Fri Oct 04 21:33:57 2019 +0000
@@ -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 @@
        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);
diff -r 93dd9bf8e47f -r a96cfbca72a7 usr.sbin/sup/source/supcparse.c
--- a/usr.sbin/sup/source/supcparse.c   Fri Oct 04 16:27:00 2019 +0000
+++ b/usr.sbin/sup/source/supcparse.c   Fri Oct 04 21:33:57 2019 +0000
@@ -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 @@
        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;
diff -r 93dd9bf8e47f -r a96cfbca72a7 usr.sbin/sup/source/supfilesrv.c
--- a/usr.sbin/sup/source/supfilesrv.c  Fri Oct 04 16:27:00 2019 +0000
+++ b/usr.sbin/sup/source/supfilesrv.c  Fri Oct 04 21:33:57 2019 +0000
@@ -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 @@
 
                /* 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 @@
                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 @@
                        (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 @@
                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 @@
                }
        }
        /* 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 @@
        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 @@
                                        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 @@
                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 @@
        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 @@
                }
                pwd = getpwnam(nbuf);
                if (pwd == NULL) {
-                       (void) sprintf(errbuf, "Reason:  Unknown user %s",
-                           nbuf);
-                       return (errbuf);
+                       snprintf(errbuf, sizeof errbuf,



Home | Main Index | Thread Index | Old Index