dcavalca / rpms / linuxptp

Forked from rpms/linuxptp 2 years ago
Clone

Blame SOURCES/linuxptp-warnings.patch

996523
commit 9ddd2a60249eaf2b2a48bf9af3843fa06cf0a095
996523
Author: Miroslav Lichvar <mlichvar@redhat.com>
996523
Date:   Wed Sep 17 11:11:15 2014 +0200
996523
996523
    Fix copying of device name to ifreq.
996523
    
996523
    Don't overwrite the last NUL with strncpy() and also replace strcpy()
996523
    with strncpy().
996523
    
996523
    Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
996523
996523
diff --git a/hwstamp_ctl.c b/hwstamp_ctl.c
996523
index ec5dd6d..0d21843 100644
996523
--- a/hwstamp_ctl.c
996523
+++ b/hwstamp_ctl.c
996523
@@ -131,7 +131,7 @@ int main(int argc, char *argv[])
996523
 	memset(&ifreq, 0, sizeof(ifreq));
996523
 	memset(&cfg, 0, sizeof(cfg));
996523
 
996523
-	strncpy(ifreq.ifr_name, device, sizeof(ifreq.ifr_name));
996523
+	strncpy(ifreq.ifr_name, device, sizeof(ifreq.ifr_name) - 1);
996523
 
996523
 	ifreq.ifr_data = (void *) &cfg;
996523
 
996523
diff --git a/sk.c b/sk.c
996523
index f694bbd..a9133fd 100644
996523
--- a/sk.c
996523
+++ b/sk.c
996523
@@ -51,7 +51,7 @@ static int hwts_init(int fd, const char *device, int rx_filter, int one_step)
996523
 	memset(&ifreq, 0, sizeof(ifreq));
996523
 	memset(&cfg, 0, sizeof(cfg));
996523
 
996523
-	strncpy(ifreq.ifr_name, device, sizeof(ifreq.ifr_name));
996523
+	strncpy(ifreq.ifr_name, device, sizeof(ifreq.ifr_name) - 1);
996523
 
996523
 	ifreq.ifr_data = (void *) &cfg;
996523
 	cfg.tx_type    = one_step ? HWTSTAMP_TX_ONESTEP_SYNC : HWTSTAMP_TX_ON;
996523
@@ -85,7 +85,7 @@ int sk_interface_index(int fd, const char *name)
996523
 	int err;
996523
 
996523
 	memset(&ifreq, 0, sizeof(ifreq));
996523
-	strcpy(ifreq.ifr_name, name);
996523
+	strncpy(ifreq.ifr_name, name, sizeof(ifreq.ifr_name) - 1);
996523
 	err = ioctl(fd, SIOCGIFINDEX, &ifreq);
996523
 	if (err < 0) {
996523
 		pr_err("ioctl SIOCGIFINDEX failed: %m");
996523
@@ -154,7 +154,7 @@ int sk_interface_macaddr(const char *name, struct address *mac)
996523
 	int err, fd;
996523
 
996523
 	memset(&ifreq, 0, sizeof(ifreq));
996523
-	strcpy(ifreq.ifr_name, name);
996523
+	strncpy(ifreq.ifr_name, name, sizeof(ifreq.ifr_name) - 1);
996523
 
996523
 	fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
996523
 	if (fd < 0) {
996523
996523
commit 6b459abc8c54189ec3315404057923c039c1796a
996523
Author: Miroslav Lichvar <mlichvar@redhat.com>
996523
Date:   Wed Sep 17 11:11:16 2014 +0200
996523
996523
    Fix Coverity warning in sk_interface_addr().
996523
    
996523
    Copy the address directly to struct sockaddr_in or sockaddr_in6 instead
996523
    of sockaddr as Coverity doesn't seem to understand the union and reports
996523
    a buffer overflow.
996523
    
996523
    Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
996523
996523
diff --git a/sk.c b/sk.c
996523
index a9133fd..c48cf45 100644
996523
--- a/sk.c
996523
+++ b/sk.c
996523
@@ -191,14 +191,15 @@ int sk_interface_addr(const char *name, int family, struct address *addr)
996523
 			switch (family) {
996523
 			case AF_INET:
996523
 				addr->len = sizeof(addr->sin);
996523
+				memcpy(&addr->sin, i->ifa_addr, addr->len);
996523
 				break;
996523
 			case AF_INET6:
996523
 				addr->len = sizeof(addr->sin6);
996523
+				memcpy(&addr->sin6, i->ifa_addr, addr->len);
996523
 				break;
996523
 			default:
996523
 				continue;
996523
 			}
996523
-			memcpy(&addr->sa, i->ifa_addr, addr->len);
996523
 			result = 0;
996523
 			break;
996523
 		}