* [PATCH] docs: networking: Replace strncpy() with strscpy()
@ 2021-06-02 20:29 Kees Cook
2021-06-03 4:40 ` Dmitry Torokhov
2021-06-04 17:22 ` Jonathan Corbet
0 siblings, 2 replies; 3+ messages in thread
From: Kees Cook @ 2021-06-02 20:29 UTC (permalink / raw)
To: Jonathan Corbet
Cc: Kees Cook, Dmitry Torokhov, Maxim Krasnyansky, Randy Dunlap,
linux-kernel, linux-doc
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>
---
Documentation/input/joydev/joystick-api.rst | 2 +-
Documentation/networking/packet_mmap.rst | 2 +-
Documentation/networking/tuntap.rst | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/Documentation/input/joydev/joystick-api.rst b/Documentation/input/joydev/joystick-api.rst
index af5934c10c1c..5db6dc6fe1c5 100644
--- a/Documentation/input/joydev/joystick-api.rst
+++ b/Documentation/input/joydev/joystick-api.rst
@@ -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);
diff --git a/Documentation/networking/packet_mmap.rst b/Documentation/networking/packet_mmap.rst
index 500ef60b1b82..c5da1a5d93de 100644
--- a/Documentation/networking/packet_mmap.rst
+++ b/Documentation/networking/packet_mmap.rst
@@ -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);
diff --git a/Documentation/networking/tuntap.rst b/Documentation/networking/tuntap.rst
index a59d1dd6fdcc..4d7087f727be 100644
--- a/Documentation/networking/tuntap.rst
+++ b/Documentation/networking/tuntap.rst
@@ -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);
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] docs: networking: Replace strncpy() with strscpy()
2021-06-02 20:29 [PATCH] docs: networking: Replace strncpy() with strscpy() Kees Cook
@ 2021-06-03 4:40 ` Dmitry Torokhov
2021-06-04 17:22 ` Jonathan Corbet
1 sibling, 0 replies; 3+ messages in thread
From: Dmitry Torokhov @ 2021-06-03 4:40 UTC (permalink / raw)
To: Kees Cook
Cc: Jonathan Corbet, Maxim Krasnyansky, Randy Dunlap, linux-kernel,
linux-doc
On Wed, Jun 02, 2021 at 01:29:14PM -0700, Kees Cook wrote:
> 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>
> ---
> Documentation/input/joydev/joystick-api.rst | 2 +-
FWIW:
Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> Documentation/networking/packet_mmap.rst | 2 +-
> Documentation/networking/tuntap.rst | 2 +-
> 3 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/Documentation/input/joydev/joystick-api.rst b/Documentation/input/joydev/joystick-api.rst
> index af5934c10c1c..5db6dc6fe1c5 100644
> --- a/Documentation/input/joydev/joystick-api.rst
> +++ b/Documentation/input/joydev/joystick-api.rst
> @@ -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);
>
>
> diff --git a/Documentation/networking/packet_mmap.rst b/Documentation/networking/packet_mmap.rst
> index 500ef60b1b82..c5da1a5d93de 100644
> --- a/Documentation/networking/packet_mmap.rst
> +++ b/Documentation/networking/packet_mmap.rst
> @@ -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);
> diff --git a/Documentation/networking/tuntap.rst b/Documentation/networking/tuntap.rst
> index a59d1dd6fdcc..4d7087f727be 100644
> --- a/Documentation/networking/tuntap.rst
> +++ b/Documentation/networking/tuntap.rst
> @@ -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);
> --
> 2.25.1
>
Thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] docs: networking: Replace strncpy() with strscpy()
2021-06-02 20:29 [PATCH] docs: networking: Replace strncpy() with strscpy() Kees Cook
2021-06-03 4:40 ` Dmitry Torokhov
@ 2021-06-04 17:22 ` Jonathan Corbet
1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Corbet @ 2021-06-04 17:22 UTC (permalink / raw)
To: Kees Cook
Cc: Kees Cook, Dmitry Torokhov, Maxim Krasnyansky, Randy Dunlap,
linux-kernel, linux-doc
Kees Cook <keescook@chromium.org> writes:
> 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>
> ---
> Documentation/input/joydev/joystick-api.rst | 2 +-
> Documentation/networking/packet_mmap.rst | 2 +-
> Documentation/networking/tuntap.rst | 2 +-
> 3 files changed, 3 insertions(+), 3 deletions(-)
Applied, thanks.
jon
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-06-04 17:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-02 20:29 [PATCH] docs: networking: Replace strncpy() with strscpy() Kees Cook
2021-06-03 4:40 ` Dmitry Torokhov
2021-06-04 17:22 ` Jonathan Corbet
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).