From: Vincent Bernat Date: Fri, 22 Nov 2013 22:37:56 +0000 (+0100) Subject: coverity: replace unsafe uses of strncpy by strlcpy X-Git-Tag: 0.7.8~72 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e2b09091a263099e12ae48522605ae4775a20988;p=thirdparty%2Flldpd.git coverity: replace unsafe uses of strncpy by strlcpy --- diff --git a/src/daemon/interfaces-linux.c b/src/daemon/interfaces-linux.c index 748d0eb3..22e9c752 100644 --- a/src/daemon/interfaces-linux.c +++ b/src/daemon/interfaces-linux.c @@ -122,7 +122,7 @@ old_iflinux_is_bridge(struct lldpd *cfg, .ifr_data = (char*)&args2 }; - strncpy(ifr.ifr_name, iface->name, IFNAMSIZ); + strlcpy(ifr.ifr_name, iface->name, IFNAMSIZ); if (ioctl(cfg->g_sock, SIOCDEVPRIVATE, &ifr) < 0) /* This can happen with a 64bit kernel and 32bit @@ -571,7 +571,7 @@ iflinux_handle_bond(struct lldpd *cfg, struct interfaces_device_list *interfaces bmaster = hardware->h_data; memset(bmaster, 0, sizeof(struct bond_master)); bmaster->index = master->index; - strncpy(bmaster->name, master->name, IFNAMSIZ); + strlcpy(bmaster->name, master->name, IFNAMSIZ); lldpd_port_cleanup(&hardware->h_lport, 0); } diff --git a/src/daemon/lldpd.c b/src/daemon/lldpd.c index 39d2d04b..849cdfc7 100644 --- a/src/daemon/lldpd.c +++ b/src/daemon/lldpd.c @@ -714,12 +714,12 @@ lldpd_get_os_release() { return NULL; } - while ((fgets(line, 1024, fp) != NULL)) { + while ((fgets(line, sizeof(line), fp) != NULL)) { key = strtok(line, "="); val = strtok(NULL, "="); - if (strncmp(key, "PRETTY_NAME", 1024) == 0) { - strncpy(release, val, 1024); + if (strncmp(key, "PRETTY_NAME", sizeof(line)) == 0) { + strlcpy(release, val, sizeof(line)); break; } }