Source-Changes-HG archive

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

[src/trunk]: src Replaced strncpy with strlcpy. Thanks to Peter Postma who



details:   https://anonhg.NetBSD.org/src/rev/55b95e406e79
branches:  trunk
changeset: 569815:55b95e406e79
user:      jrf <jrf%NetBSD.org@localhost>
date:      Tue Sep 07 13:20:39 2004 +0000

description:
Replaced strncpy with strlcpy.  Thanks to Peter Postma who
pointed them our in PR #25762. Approved by christos%NetBSD.org@localhost.

diffstat:

 games/atc/log.c                      |   7 +++----
 games/sail/dr_1.c                    |   8 +++-----
 games/sail/sync.c                    |  14 ++++++--------
 lib/libc/gen/sysctl.c                |   7 +++----
 lib/libpcap/inet.c                   |  10 ++++------
 lib/libwrap/diag.c                   |   7 +++----
 libexec/rpc.rquotad/rquotad.c        |   7 +++----
 sbin/modload/modload.c               |   8 ++++----
 usr.bin/quota/quota.c                |   7 +++----
 usr.bin/tip/tip.c                    |   7 +++----
 usr.sbin/rarpd/rarpd.c               |   7 +++----
 usr.sbin/rpc.bootparamd/bootparamd.c |  13 +++++--------
 usr.sbin/tpctl/tp.c                  |   7 +++----
 usr.sbin/ypbind/ypbind.c             |   7 +++----
 usr.sbin/ypserv/ypserv/ypserv_db.c   |   7 +++----
 usr.sbin/ypset/ypset.c               |   7 +++----
 16 files changed, 55 insertions(+), 75 deletions(-)

diffs (truncated from 491 to 300 lines):

diff -r 5debe87979bd -r 55b95e406e79 games/atc/log.c
--- a/games/atc/log.c   Tue Sep 07 12:28:34 2004 +0000
+++ b/games/atc/log.c   Tue Sep 07 13:20:39 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: log.c,v 1.12 2003/08/07 09:36:54 agc Exp $     */
+/*     $NetBSD: log.c,v 1.13 2004/09/07 13:20:39 jrf Exp $     */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -46,7 +46,7 @@
 #if 0
 static char sccsid[] = "@(#)log.c      8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: log.c,v 1.12 2003/08/07 09:36:54 agc Exp $");
+__RCSID("$NetBSD: log.c,v 1.13 2004/09/07 13:20:39 jrf Exp $");
 #endif
 #endif /* not lint */
 
@@ -180,8 +180,7 @@
                }
                strcpy(thisscore.name, pw->pw_name);
                uname(&name);
-               strncpy(thisscore.host, name.nodename, sizeof(thisscore.host)-1);
-               thisscore.host[sizeof(thisscore.host) - 1] = '\0';
+               strlcpy(thisscore.host, name.nodename, sizeof(thisscore.host));
 
                cp = strrchr(file, '/');
                if (cp == NULL) {
diff -r 5debe87979bd -r 55b95e406e79 games/sail/dr_1.c
--- a/games/sail/dr_1.c Tue Sep 07 12:28:34 2004 +0000
+++ b/games/sail/dr_1.c Tue Sep 07 13:20:39 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dr_1.c,v 1.19 2003/08/07 09:37:41 agc Exp $    */
+/*     $NetBSD: dr_1.c,v 1.20 2004/09/07 13:20:39 jrf Exp $    */
 
 /*
  * Copyright (c) 1983, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)dr_1.c     8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: dr_1.c,v 1.19 2003/08/07 09:37:41 agc Exp $");
+__RCSID("$NetBSD: dr_1.c,v 1.20 2004/09/07 13:20:39 jrf Exp $");
 #endif
 #endif /* not lint */
 
@@ -429,10 +429,8 @@
                                        *tp = toupper(*tp);
                                p = tp;
                        }
-                       strncpy(bestship->file->captain, p,
+                       strlcpy(bestship->file->captain, p,
                                sizeof bestship->file->captain);
-                       bestship->file->captain
-                               [sizeof bestship->file->captain - 1] = 0;
                        logger(bestship);
                }
                return -1;
diff -r 5debe87979bd -r 55b95e406e79 games/sail/sync.c
--- a/games/sail/sync.c Tue Sep 07 12:28:34 2004 +0000
+++ b/games/sail/sync.c Tue Sep 07 13:20:39 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sync.c,v 1.22 2004/01/27 20:27:59 jsm Exp $    */
+/*     $NetBSD: sync.c,v 1.23 2004/09/07 13:20:39 jrf Exp $    */
 
 /*
  * Copyright (c) 1983, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)sync.c     8.2 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: sync.c,v 1.22 2004/01/27 20:27:59 jsm Exp $");
+__RCSID("$NetBSD: sync.c,v 1.23 2004/09/07 13:20:39 jrf Exp $");
 #endif
 #endif /* not lint */
 
@@ -379,9 +379,8 @@
                break;
                }
        case W_CAPTAIN:
-               strncpy(ship->file->captain, astr,
-                       sizeof ship->file->captain - 1);
-               ship->file->captain[sizeof ship->file->captain - 1] = 0;
+               strlcpy(ship->file->captain, astr,
+                       sizeof ship->file->captain);
                break;
        case W_CAPTURED:
                if (a < 0)
@@ -418,9 +417,8 @@
                ship->specs->hull = a;
                break;
        case W_MOVE:
-               strncpy(ship->file->movebuf, astr,
-                       sizeof ship->file->movebuf - 1);
-               ship->file->movebuf[sizeof ship->file->movebuf - 1] = 0;
+               strlcpy(ship->file->movebuf, astr,
+                       sizeof ship->file->movebuf);
                break;
        case W_PCREW:
                ship->file->pcrew = a;
diff -r 5debe87979bd -r 55b95e406e79 lib/libc/gen/sysctl.c
--- a/lib/libc/gen/sysctl.c     Tue Sep 07 12:28:34 2004 +0000
+++ b/lib/libc/gen/sysctl.c     Tue Sep 07 13:20:39 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sysctl.c,v 1.26 2004/04/25 05:47:52 atatat Exp $       */
+/*     $NetBSD: sysctl.c,v 1.27 2004/09/07 13:20:39 jrf Exp $  */
 
 /*-
  * Copyright (c) 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)sysctl.c   8.2 (Berkeley) 1/4/94";
 #else
-__RCSID("$NetBSD: sysctl.c,v 1.26 2004/04/25 05:47:52 atatat Exp $");
+__RCSID("$NetBSD: sysctl.c,v 1.27 2004/09/07 13:20:39 jrf Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -317,10 +317,9 @@
                        if (sysctl_usermib[ni].sysctl_desc == NULL)
                                d1->descr_len = 1;
                        else {
-                               strncpy(d1->descr_str,
+                               (void)strlcpy(d1->descr_str,
                                        sysctl_usermib[ni].sysctl_desc,
                                        sizeof(buf) - sizeof(*d1));
-                               buf[sizeof(buf) - 1] = '\0';
                                d1->descr_len = strlen(d1->descr_str) + 1;
                        }
                        d = (size_t)__sysc_desc_adv(NULL, d1->descr_len);
diff -r 5debe87979bd -r 55b95e406e79 lib/libpcap/inet.c
--- a/lib/libpcap/inet.c        Tue Sep 07 12:28:34 2004 +0000
+++ b/lib/libpcap/inet.c        Tue Sep 07 13:20:39 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: inet.c,v 1.8 2000/04/13 05:14:19 itojun Exp $  */
+/*     $NetBSD: inet.c,v 1.9 2004/09/07 13:20:40 jrf Exp $     */
 
 /*
  * Copyright (c) 1994, 1995, 1996, 1997
@@ -39,7 +39,7 @@
 static const char rcsid[] =
     "@(#) Header: inet.c,v 1.21 97/07/17 14:24:58 leres Exp  (LBL)";
 #else
-__RCSID("$NetBSD: inet.c,v 1.8 2000/04/13 05:14:19 itojun Exp $");
+__RCSID("$NetBSD: inet.c,v 1.9 2004/09/07 13:20:40 jrf Exp $");
 #endif
 #endif
 
@@ -137,8 +137,7 @@
                return (NULL);
        }
 
-       (void)strncpy(device, mp->ifa_name, sizeof(device) - 1);
-       device[sizeof(device) - 1] = '\0';
+       (void)strlcpy(device, mp->ifa_name, sizeof(device));
        freeifaddrs(ifap);
        return (device);
 #else
@@ -220,8 +219,7 @@
                return (NULL);
        }
 
-       (void)strncpy(device, mp->ifr_name, sizeof(device) - 1);
-       device[sizeof(device) - 1] = '\0';
+       (void)strlcpy(device, mp->ifr_name, sizeof(device));
        return (device);
 #endif
 }
diff -r 5debe87979bd -r 55b95e406e79 lib/libwrap/diag.c
--- a/lib/libwrap/diag.c        Tue Sep 07 12:28:34 2004 +0000
+++ b/lib/libwrap/diag.c        Tue Sep 07 13:20:39 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: diag.c,v 1.7 2001/09/24 17:55:47 atatat Exp $  */
+/*     $NetBSD: diag.c,v 1.8 2004/09/07 13:20:40 jrf Exp $     */
 
  /*
   * Routines to report various classes of problems. Each report is decorated
@@ -16,7 +16,7 @@
 #if 0
 static char sccsid[] = "@(#) diag.c 1.1 94/12/28 17:42:20";
 #else
-__RCSID("$NetBSD: diag.c,v 1.7 2001/09/24 17:55:47 atatat Exp $");
+__RCSID("$NetBSD: diag.c,v 1.8 2004/09/07 13:20:40 jrf Exp $");
 #endif
 #endif
 
@@ -75,8 +75,7 @@
 
     /* append format and force null termination */
     fmt[o] = '\0';
-    strncat(fmt, format, sizeof(fmt) - o);
-    fmt[sizeof(fmt) - 1] = '\0';
+    (void)strlcat(fmt, format, sizeof(fmt) - o);
 
     errno = oerrno;
     vsyslog(severity, fmt, ap);
diff -r 5debe87979bd -r 55b95e406e79 libexec/rpc.rquotad/rquotad.c
--- a/libexec/rpc.rquotad/rquotad.c     Tue Sep 07 12:28:34 2004 +0000
+++ b/libexec/rpc.rquotad/rquotad.c     Tue Sep 07 13:20:39 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rquotad.c,v 1.21 2003/09/20 22:25:29 bouyer Exp $      */
+/*     $NetBSD: rquotad.c,v 1.22 2004/09/07 13:20:40 jrf Exp $ */
 
 /*
  * by Manuel Bouyer (bouyer%ensta.fr@localhost). Public domain.
@@ -6,7 +6,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: rquotad.c,v 1.21 2003/09/20 22:25:29 bouyer Exp $");
+__RCSID("$NetBSD: rquotad.c,v 1.22 2004/09/07 13:20:40 jrf Exp $");
 #endif
 
 #include <sys/param.h>
@@ -376,8 +376,7 @@
 
        *uqfnamep = NULL;
        *gqfnamep = NULL;
-       strncpy(buf, fs->fs_mntops, sizeof(buf) - 1);
-       buf[sizeof(buf) - 1] = '\0';
+       (void)strlcpy(buf, fs->fs_mntops, sizeof(buf));
        for (opt = strtok(buf, ","); opt; opt = strtok(NULL, ",")) {
                if ((cp = strchr(opt, '=')))
                        *cp++ = '\0';
diff -r 5debe87979bd -r 55b95e406e79 sbin/modload/modload.c
--- a/sbin/modload/modload.c    Tue Sep 07 12:28:34 2004 +0000
+++ b/sbin/modload/modload.c    Tue Sep 07 13:20:39 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: modload.c,v 1.47 2004/06/28 19:27:06 nathanw Exp $     */
+/*     $NetBSD: modload.c,v 1.48 2004/09/07 13:20:41 jrf Exp $ */
 
 /*
  * Copyright (c) 1993 Terrence R. Lambert.
@@ -34,7 +34,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: modload.c,v 1.47 2004/06/28 19:27:06 nathanw Exp $");
+__RCSID("$NetBSD: modload.c,v 1.48 2004/09/07 13:20:41 jrf Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -321,8 +321,8 @@
                err(3, _PATH_LKM);
        fileopen |= DEV_OPEN;
 
-       strncpy(modout, modobj, sizeof(modout) - 1);
-       modout[sizeof(modout) - 1] = '\0';
+       if (strlcpy(modout, modobj, sizeof(modout)) >= sizeof(modout))
+               errx(1, "program name is too big for buffer");
 
        p = strrchr(modout, '.');
        if (!p || strcmp(p, ".o"))
diff -r 5debe87979bd -r 55b95e406e79 usr.bin/quota/quota.c
--- a/usr.bin/quota/quota.c     Tue Sep 07 12:28:34 2004 +0000
+++ b/usr.bin/quota/quota.c     Tue Sep 07 13:20:39 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: quota.c,v 1.29 2004/04/21 01:05:47 christos Exp $      */
+/*     $NetBSD: quota.c,v 1.30 2004/09/07 13:20:40 jrf Exp $   */
 
 /*
  * Copyright (c) 1980, 1990, 1993
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)quota.c    8.4 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: quota.c,v 1.29 2004/04/21 01:05:47 christos Exp $");
+__RCSID("$NetBSD: quota.c,v 1.30 2004/09/07 13:20:40 jrf Exp $");
 #endif
 #endif /* not lint */
 
@@ -534,8 +534,7 @@
                    qfextension[GRPQUOTA], qfname);
                initname = 1;
        }
-       (void)strncpy(buf, fs->fs_mntops, sizeof(buf) - 1);
-       buf[sizeof(buf) - 1] = '\0';
+       (void)strlcpy(buf, fs->fs_mntops, sizeof(buf));
        for (opt = strtok(buf, ","); opt; opt = strtok(NULL, ",")) {
                if ((cp = strchr(opt, '=')) != NULL)
                        *cp++ = '\0';
diff -r 5debe87979bd -r 55b95e406e79 usr.bin/tip/tip.c
--- a/usr.bin/tip/tip.c Tue Sep 07 12:28:34 2004 +0000
+++ b/usr.bin/tip/tip.c Tue Sep 07 13:20:39 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tip.c,v 1.26 2004/04/23 22:24:34 christos Exp $        */
+/*     $NetBSD: tip.c,v 1.27 2004/09/07 13:20:40 jrf Exp $     */
 
 /*
  * Copyright (c) 1983, 1993
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)tip.c      8.1 (Berkeley) 6/6/93";
 #endif
-__RCSID("$NetBSD: tip.c,v 1.26 2004/04/23 22:24:34 christos Exp $");
+__RCSID("$NetBSD: tip.c,v 1.27 2004/09/07 13:20:40 jrf Exp $");
 #endif /* not lint */
 
 /*
@@ -133,8 +133,7 @@



Home | Main Index | Thread Index | Old Index