Skip to contentSkip to conversation

kexec-tools: Fix possible out-of-bounds access in ifdown

PATCH Applied Helge Deller 2 participants 2 messages Oct 1, 2019 – Oct 3, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kexec-tools: Fix possible out-of-bounds access in ifdown

Fix a possible out-of-bounds access in function ifdown():

ifdown.c: In function 'ifdown':
ifdown.c:56:4: warning: 'strncpy' specified bound 16 equals destination size [-Wstringop-truncation]
56 | strncpy(ifr.ifr_name, ifp->if_name, IFNAMSIZ);

kexec/ifdown.c +2 -1
index 9679ad7..3ac19c1 100644
@@ -53,7 +53,8 @@ int ifdown(void)
 			if (strchr(ifp->if_name, ':') != NULL)
 				continue;
 
-			strncpy(ifr.ifr_name, ifp->if_name, IFNAMSIZ);
+			strncpy(ifr.ifr_name, ifp->if_name, IFNAMSIZ-1);
+			ifr.ifr_name[IFNAMSIZ-1] = 0;
 			if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
 				fprintf(stderr, "ifdown: shutdown ");
 				perror(ifp->if_name);

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

Applied
#1 lore raw
Quoted 6 lines · Helge Deller

Fix a possible out-of-bounds access in function ifdown():

ifdown.c: In function 'ifdown':
ifdown.c:56:4: warning: 'strncpy' specified bound 16 equals destination size [-Wstringop-truncation]
56 | strncpy(ifr.ifr_name, ifp->if_name, IFNAMSIZ);

Thanks, applied.

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec