Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

docs: networking: Replace strncpy() with strscpy()

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>

authored by

Kees Cook and committed by
Jonathan Corbet
f9ce26c5 709dedfd

+3 -3
+1 -1
Documentation/input/joydev/joystick-api.rst
··· 263 263 264 264 char name[128]; 265 265 if (ioctl(fd, JSIOCGNAME(sizeof(name)), name) < 0) 266 - strncpy(name, "Unknown", sizeof(name)); 266 + strscpy(name, "Unknown", sizeof(name)); 267 267 printf("Name: %s\n", name); 268 268 269 269
+1 -1
Documentation/networking/packet_mmap.rst
··· 153 153 struct ifreq s_ifr; 154 154 ... 155 155 156 - strncpy (s_ifr.ifr_name, "eth0", sizeof(s_ifr.ifr_name)); 156 + strscpy_pad (s_ifr.ifr_name, "eth0", sizeof(s_ifr.ifr_name)); 157 157 158 158 /* get interface index of eth0 */ 159 159 ioctl(this->socket, SIOCGIFINDEX, &s_ifr);
+1 -1
Documentation/networking/tuntap.rst
··· 107 107 */ 108 108 ifr.ifr_flags = IFF_TUN; 109 109 if( *dev ) 110 - strncpy(ifr.ifr_name, dev, IFNAMSIZ); 110 + strscpy_pad(ifr.ifr_name, dev, IFNAMSIZ); 111 111 112 112 if( (err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0 ){ 113 113 close(fd);