Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/sysinst Use a few strlcpy() instead of strncpy() fo...



details:   https://anonhg.NetBSD.org/src/rev/eb9053c16324
branches:  trunk
changeset: 968758:eb9053c16324
user:      martin <martin%NetBSD.org@localhost>
date:      Mon Jan 27 21:30:17 2020 +0000

description:
Use a few strlcpy() instead of strncpy() for network ioctl structs.
We seem to have no formal documentation stating the various

        char if*_name[IFNAMSIZ]; /* if name, e.g. "en0" */

elements in ioctls are nul terminated, but the peanut gallery claims
it is so - and at least half of the code in-tree touching them agrees.

diffstat:

 usr.sbin/sysinst/net.c |  8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diffs (36 lines):

diff -r 24dc768c25f1 -r eb9053c16324 usr.sbin/sysinst/net.c
--- a/usr.sbin/sysinst/net.c    Mon Jan 27 21:21:21 2020 +0000
+++ b/usr.sbin/sysinst/net.c    Mon Jan 27 21:30:17 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: net.c,v 1.34 2019/11/16 20:26:59 martin Exp $  */
+/*     $NetBSD: net.c,v 1.35 2020/01/27 21:30:17 martin Exp $  */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -279,7 +279,7 @@
                return -1;
 
        memset(ifr, 0, sizeof *ifr);
-       strncpy(ifr->ifr_name, net_dev, sizeof ifr->ifr_name);
+       strlcpy(ifr->ifr_name, net_dev, sizeof ifr->ifr_name);
        rval = ioctl(sock, cmd, ifr);
        close(sock);
 
@@ -297,7 +297,7 @@
                return -1;
 
        memset(ifmr, 0, sizeof *ifmr);
-       strncpy(ifmr->ifm_name, net_dev, sizeof ifmr->ifm_name);
+       strlcpy(ifmr->ifm_name, net_dev, sizeof ifmr->ifm_name);
        rval = ioctl(sock, cmd, ifmr);
        close(sock);
 
@@ -539,7 +539,7 @@
        network_up = 1;
        dhcp_config = 0;
 
-       strncpy(net_dev, net_devs[selected_net].if_dev, STRSIZE);
+       strlcpy(net_dev, net_devs[selected_net].if_dev, sizeof net_dev);
 
        if (!handle_license(net_dev))
                goto done;



Home | Main Index | Thread Index | Old Index