[LEDE-DEV] [PATCH] dhcpv6: Fix strncpy bounds and initialize struct to 0
Khem Raj
raj.khem at gmail.com
Sat Apr 21 01:54:37 PDT 2018
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 at gmail.com>
---
src/dhcpv6.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
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;
--
2.17.0
More information about the Lede-dev
mailing list