All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/9] utils/can: prevent unterminated destination buffer with strncpy()
@ 2018-10-26 14:08 Philippe Gerum
  2018-10-26 14:08 ` [PATCH 2/9] demos/posix: " Philippe Gerum
                   ` (7 more replies)
  0 siblings, 8 replies; 15+ messages in thread
From: Philippe Gerum @ 2018-10-26 14:08 UTC (permalink / raw)
  To: xenomai; +Cc: Jan Kiszka, Philippe Gerum

GCC 8.x introduced -Wstringop-truncation to help detecting likely
unwanted outcomes of strncpy(dst, src, n), such as omitting the NUL
character into the destination buffer whenever n < sizeof(src).

Fix unsafe strncpy() calls when we do expect a null-terminated
destination buffer.
---
 utils/can/rtcanconfig.c | 7 ++++---
 utils/can/rtcanrecv.c   | 3 ++-
 utils/can/rtcansend.c   | 3 ++-
 3 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/utils/can/rtcanconfig.c b/utils/can/rtcanconfig.c
index a285ec73d..395e0368d 100644
--- a/utils/can/rtcanconfig.c
+++ b/utils/can/rtcanconfig.c
@@ -31,6 +31,7 @@
 #include <errno.h>
 #include <getopt.h>
 #include <sys/mman.h>
+#include <boilerplate/ancillaries.h>
 
 #include <rtdm/can.h>
 
@@ -81,7 +82,7 @@ static int string_to_ctrlmode(char *str)
 
 int main(int argc, char *argv[])
 {
-    char    ifname[16];
+    char    ifname[IFNAMSIZ];
     int     can_fd = -1;
     int     new_baudrate = -1;
     int     new_mode = -1;
@@ -159,8 +160,8 @@ int main(int argc, char *argv[])
 	return 0;
     }
 
-    strncpy(ifname, argv[optind], IFNAMSIZ);
-    strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
+    namecpy(ifname, argv[optind]);
+    namecpy(ifr.ifr_name, ifname);
 
     if (optind == argc - 2) {   /* Get mode setting */
 	new_mode = string_to_mode(argv[optind + 1]);
diff --git a/utils/can/rtcanrecv.c b/utils/can/rtcanrecv.c
index 8155ab76d..71e68cc5c 100644
--- a/utils/can/rtcanrecv.c
+++ b/utils/can/rtcanrecv.c
@@ -7,6 +7,7 @@
 #include <getopt.h>
 
 #include <alchemy/task.h>
+#include <boilerplate/ancillaries.h>
 
 #include <rtdm/can.h>
 
@@ -248,7 +249,7 @@ int main(int argc, char **argv)
 	if (verbose)
 	    printf("interface %s\n", argv[optind]);
 
-	strncpy(ifr.ifr_name, argv[optind], IFNAMSIZ);
+	namecpy(ifr.ifr_name, argv[optind]);
 	if (verbose)
 	    printf("s=%d, ifr_name=%s\n", s, ifr.ifr_name);
 
diff --git a/utils/can/rtcansend.c b/utils/can/rtcansend.c
index 4a692b3bf..bfa3054c2 100644
--- a/utils/can/rtcansend.c
+++ b/utils/can/rtcansend.c
@@ -6,6 +6,7 @@
 #include <errno.h>
 #include <getopt.h>
 
+#include <boilerplate/ancillaries.h>
 #include <alchemy/task.h>
 #include <alchemy/timer.h>
 
@@ -231,7 +232,7 @@ int main(int argc, char **argv)
 	    printf("Using loopback=%d\n", loopback);
     }
 
-    strncpy(ifr.ifr_name, argv[optind], IFNAMSIZ);
+    namecpy(ifr.ifr_name, argv[optind]);
     if (verbose)
 	printf("s=%d, ifr_name=%s\n", s, ifr.ifr_name);
 
-- 
2.17.2



^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2019-01-24 18:35 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-26 14:08 [PATCH 1/9] utils/can: prevent unterminated destination buffer with strncpy() Philippe Gerum
2018-10-26 14:08 ` [PATCH 2/9] demos/posix: " Philippe Gerum
2018-10-26 14:08 ` [PATCH 3/9] boilerplate/ancillaries: prevent false positive with -Wstringop-truncation Philippe Gerum
2018-10-26 14:08 ` [PATCH 4/9] cobalt/ancillaries: " Philippe Gerum
2019-01-24 18:35   ` Jan Kiszka
2018-10-26 14:08 ` [PATCH 5/9] boilerplate/compiler: drop __const and __pure shorthands Philippe Gerum
2018-10-26 14:08 ` [PATCH 6/9] net/stack: export services to switch interface up/down Philippe Gerum
2018-10-26 14:08 ` [PATCH 7/9] net/stack: ignore extraneous interface UP/DOWN calls Philippe Gerum
2018-10-26 14:08 ` [PATCH 8/9] net/igb: down interface upon PCI unregister Philippe Gerum
2018-10-31 12:32   ` Jan Kiszka
2018-10-31 14:18     ` Philippe Gerum
2018-10-31 15:10       ` Jan Kiszka
2018-10-31 16:32         ` Philippe Gerum
2018-10-31 16:40           ` Jan Kiszka
2018-10-26 14:08 ` [PATCH 9/9] net/igb: igb_ioctl() requires execution in secondary mode Philippe Gerum

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.