diff mbox series

[LEDE-DEV] dhcpv6: Fix strncpy bounds and initialize struct to 0

Message ID 20180421085437.44001-1-raj.khem@gmail.com
State Superseded
Headers show
Series [LEDE-DEV] dhcpv6: Fix strncpy bounds and initialize struct to 0 | expand

Commit Message

Khem Raj April 21, 2018, 8:54 a.m. UTC
Fixes
dhcpv6.c:141:2: error: 'strncpy' specified bound 16 equals destination size [-Werror=stringop-truncation]                                                                                                        strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));

Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 src/dhcpv6.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/src/dhcpv6.c b/src/dhcpv6.c
index e8f32a3..e55b7e1 100644
--- a/src/dhcpv6.c
+++ b/src/dhcpv6.c
@@ -137,7 +137,8 @@  int init_dhcpv6(const char *ifname, unsigned int options, int sol_timeout)
 
 	// Detect interface
 	struct ifreq ifr;
-	strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+	memset(&ifr, 0, sizeof(struct ifreq));
+	strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)-1);
 	if (ioctl(sock, SIOCGIFINDEX, &ifr) < 0)
 		return -1;
 	ifindex = ifr.ifr_ifindex;