dhcp-4.4.1-fix-string-truncations-1.patch 1.96 KB
GCC 8.1 introduces some additional diagnostics around possible string
truncation with strncpy, which trigger errors in a few places in DHCP.
This patch clears up the errors, hopefully without introducing bugs.

diff -r -N -u dhcp-4.4.1-orig/common/discover.c dhcp-4.4.1/common/discover.c
--- dhcp-4.4.1-orig/common/discover.c	2018-02-21 08:30:46.000000000 -0600
+++ dhcp-4.4.1/common/discover.c	2018-05-26 10:27:50.878733725 -0500
@@ -234,7 +234,7 @@
  * Structure used to return information about a specific interface.
  */
 struct iface_info {
-	char name[IF_NAMESIZE+1];	/* name of the interface, e.g. "bge0" */
+	char name[IF_NAMESIZE+2];	/* name of the interface, e.g. "bge0" */
 	struct sockaddr_storage addr;	/* address information */
 	isc_uint64_t flags;		/* interface flags, e.g. IFF_LOOPBACK */
 };
@@ -643,7 +643,7 @@
 				log_fatal("Error allocating interface %s: %s",
 					  info.name, isc_result_totext(status));
 			}
-			strncpy(tmp->name, info.name, sizeof(tmp->name) - 1);
+			strncpy(tmp->name, info.name, sizeof(tmp->name));
 			interface_snorf(tmp, ir);
 			interface_dereference(&tmp, MDL);
 			tmp = interfaces; /* XXX */
diff -r -N -u dhcp-4.4.1-orig/common/parse.c dhcp-4.4.1/common/parse.c
--- dhcp-4.4.1-orig/common/parse.c	2018-02-21 08:30:46.000000000 -0600
+++ dhcp-4.4.1/common/parse.c	2018-05-26 10:29:04.083422523 -0500
@@ -5567,7 +5567,7 @@
 	va_list list;
 	char lexbuf [256];
 	char mbuf [1024];
-	char fbuf [1024];
+	char fbuf [2048];
 	unsigned i, lix;
 	
 	do_percentm (mbuf, fmt);
diff -r -N -u dhcp-4.4.1-orig/relay/dhcrelay.c dhcp-4.4.1/relay/dhcrelay.c
--- dhcp-4.4.1-orig/relay/dhcrelay.c	2018-02-21 08:30:46.000000000 -0600
+++ dhcp-4.4.1/relay/dhcrelay.c	2018-05-26 10:30:42.832339929 -0500
@@ -2102,7 +2102,7 @@
  */
 void request_v4_interface(const char* name, int flags) {
         struct interface_info *tmp = NULL;
-        int len = strlen(name);
+        int len = strlen(name) - 1;
         isc_result_t status;
 
         if (len >= sizeof(tmp->name)) {