docs: networking: Replace strncpy() with strscpy()
authorKees Cook <keescook@chromium.org>
Wed, 2 Jun 2021 20:29:14 +0000 (13:29 -0700)
committerJonathan Corbet <corbet@lwn.net>
Fri, 4 Jun 2021 17:21:43 +0000 (11:21 -0600)
Replace example code's use of strncpy() with strscpy() functions. Using
strncpy() is considered deprecated:
https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings

Signed-off-by: Kees Cook <keescook@chromium.org>
Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Link: https://lore.kernel.org/r/20210602202914.4079123-1-keescook@chromium.org
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Documentation/input/joydev/joystick-api.rst
Documentation/networking/packet_mmap.rst
Documentation/networking/tuntap.rst

index af5934c..5db6dc6 100644 (file)
@@ -263,7 +263,7 @@ possible overrun should the name be too long::
 
        char name[128];
        if (ioctl(fd, JSIOCGNAME(sizeof(name)), name) < 0)
-               strncpy(name, "Unknown", sizeof(name));
+               strscpy(name, "Unknown", sizeof(name));
        printf("Name: %s\n", name);
 
 
index 500ef60..c5da1a5 100644 (file)
@@ -153,7 +153,7 @@ As capture, each frame contains two parts::
     struct ifreq s_ifr;
     ...
 
-    strncpy (s_ifr.ifr_name, "eth0", sizeof(s_ifr.ifr_name));
+    strscpy_pad (s_ifr.ifr_name, "eth0", sizeof(s_ifr.ifr_name));
 
     /* get interface index of eth0 */
     ioctl(this->socket, SIOCGIFINDEX, &s_ifr);
index a59d1dd..4d7087f 100644 (file)
@@ -107,7 +107,7 @@ Note that the character pointer becomes overwritten with the real device name
        */
       ifr.ifr_flags = IFF_TUN;
       if( *dev )
-        strncpy(ifr.ifr_name, dev, IFNAMSIZ);
+        strscpy_pad(ifr.ifr_name, dev, IFNAMSIZ);
 
       if( (err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0 ){
         close(fd);