Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/pkg_install/lib - use snprintf and strlcpy instead ...



details:   https://anonhg.NetBSD.org/src/rev/d5345b6f4ee7
branches:  trunk
changeset: 533757:d5345b6f4ee7
user:      yamt <yamt%NetBSD.org@localhost>
date:      Tue Jul 09 03:30:05 2002 +0000

description:
- use snprintf and strlcpy instead of strcpy, strcat and sprintf in some place.
- remove a unneeded strcpy.

diffstat:

 usr.sbin/pkg_install/lib/file.c  |  40 ++++++++++++++++++++--------------------
 usr.sbin/pkg_install/lib/ftpio.c |   6 +++---
 2 files changed, 23 insertions(+), 23 deletions(-)

diffs (118 lines):

diff -r 139a2a0600b6 -r d5345b6f4ee7 usr.sbin/pkg_install/lib/file.c
--- a/usr.sbin/pkg_install/lib/file.c   Tue Jul 09 02:28:08 2002 +0000
+++ b/usr.sbin/pkg_install/lib/file.c   Tue Jul 09 03:30:05 2002 +0000
@@ -1,11 +1,11 @@
-/*     $NetBSD: file.c,v 1.52 2002/06/10 09:14:27 yamt Exp $   */
+/*     $NetBSD: file.c,v 1.53 2002/07/09 03:30:05 yamt Exp $   */
 
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static const char *rcsid = "from FreeBSD Id: file.c,v 1.29 1997/10/08 07:47:54 charnier Exp";
 #else
-__RCSID("$NetBSD: file.c,v 1.52 2002/06/10 09:14:27 yamt Exp $");
+__RCSID("$NetBSD: file.c,v 1.53 2002/07/09 03:30:05 yamt Exp $");
 #endif
 #endif
 
@@ -256,7 +256,7 @@
                 * now we need to construct a composite one out of that and
                 * the basename we were handed as a dependency. */
                if (base) {
-                       strcpy(fname, base);
+                       strlcpy(fname, base, sizeof(fname));
                        /* Advance back two slashes to get to the root of the package hierarchy */
                        cp = strrchr(fname, '/');
                        if (cp) {
@@ -264,20 +264,20 @@
                                cp = strrchr(fname, '/');
                        }
                        if (cp) {
-                               *(cp + 1) = '\0';
-                               strcat(cp, "All/");
-                               strcat(cp, spec);
-                               strcat(cp, sfx);
+                               size_t sz;
+
+                               cp++; /* next char of '/' */
+                               sz = fname + sizeof(fname) - cp;
+                               snprintf(cp, sz, "All/%s%s", spec, sfx);
                        } else
                                return NULL;
                } else {
                        /* Otherwise, we've been given an environment variable hinting at the right location from sysinstall */
-                       strcpy(fname, hint);
-                       strcat(fname, spec);
-                       strcat(fname, sfx);
+                       assert(hint != NULL);
+                       snprintf(fname, sizeof(fname), "%s%s%s", hint, spec, sfx);
                }
        } else
-               strcpy(fname, spec);
+               strlcpy(fname, spec, sizeof(fname));
 
        /* Some sanity checks on the URL */
        cp = fileURLHost(fname, host, MAXHOSTNAMELEN);
@@ -367,10 +367,11 @@
                        cp = strrchr(tmp, '/');
                }
                if (cp) {
-                       *(cp + 1) = '\0';
-                       strcat(cp, "All/");
-                       strcat(cp, fname);
-                       strcat(cp, ".t[bg]z");
+                       size_t sz;
+
+                       cp++; /* next char of '/' */
+                       sz = fname + sizeof(fname) - cp;
+                       snprintf(cp, sz, "All/%s.t[bg]z", fname);
 
                        if (ispkgpattern(tmp)) {
                                if (IS_URL(tmp)) {
@@ -658,10 +659,9 @@
 int
 unpack(char *pkg, char *flist)
 {
-       char    args[10], suff[80], *cp;
+       char    args[10] = "-";
+       char   *cp;
 
-       args[0] = '-';
-       args[1] = '\0';
        /*
          * Figure out by a crude heuristic whether this or not this is probably
          * compressed.
@@ -669,8 +669,8 @@
        if (strcmp(pkg, "-")) {
                cp = strrchr(pkg, '.');
                if (cp) {
-                       strcpy(suff, cp + 1);
-                       if (strchr(suff, 'z') || strchr(suff, 'Z'))
+                       cp++;
+                       if (strchr(cp, 'z') || strchr(cp, 'Z'))
                                strcat(args, "z");
                }
        } else
diff -r 139a2a0600b6 -r d5345b6f4ee7 usr.sbin/pkg_install/lib/ftpio.c
--- a/usr.sbin/pkg_install/lib/ftpio.c  Tue Jul 09 02:28:08 2002 +0000
+++ b/usr.sbin/pkg_install/lib/ftpio.c  Tue Jul 09 03:30:05 2002 +0000
@@ -1,8 +1,8 @@
-/*     $NetBSD: ftpio.c,v 1.38 2002/06/21 14:49:41 agc Exp $   */
+/*     $NetBSD: ftpio.c,v 1.39 2002/07/09 03:30:06 yamt Exp $  */
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: ftpio.c,v 1.38 2002/06/21 14:49:41 agc Exp $");
+__RCSID("$NetBSD: ftpio.c,v 1.39 2002/07/09 03:30:06 yamt Exp $");
 #endif
 
 /*
@@ -615,7 +615,7 @@
        if (best[0] != '\0') {
                if (Verbose)
                        printf("best match: '%s%s'\n", base, best);
-               sprintf(expandedurl, "%s%s", base, best);
+               snprintf(expandedurl, FILENAME_MAX, "%s%s", base, best);
        }
     }
 



Home | Main Index | Thread Index | Old Index