Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 18 May 2016 23:35:37 +0000 (UTC)
From:      "Conrad E. Meyer" <cem@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r300172 - head/sbin/dhclient
Message-ID:  <201605182335.u4INZbv8075515@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: cem
Date: Wed May 18 23:35:37 2016
New Revision: 300172
URL: https://svnweb.freebsd.org/changeset/base/300172

Log:
  Revert r299512
  
  It broke client identifiers because I misunderstood the intent of the code.
  There is still a minor issue detected by Coverity (at least, I can't find where
  the code proves it isn't an issue).  I'll follow up with a better fix for the
  CIDs.
  
  Reported by:	Ian FREISLICH
  Sponsored by:	EMC / Isilon Storage Division

Modified:
  head/sbin/dhclient/dhclient.c

Modified: head/sbin/dhclient/dhclient.c
==============================================================================
--- head/sbin/dhclient/dhclient.c	Wed May 18 22:50:25 2016	(r300171)
+++ head/sbin/dhclient/dhclient.c	Wed May 18 23:35:37 2016	(r300172)
@@ -56,8 +56,6 @@
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
-#include <stddef.h>
-
 #include "dhcpd.h"
 #include "privsep.h"
 
@@ -1572,18 +1570,16 @@ make_discover(struct interface_info *ip,
 	}
 
 	/* set unique client identifier */
-	struct hardware client_ident;
+	char client_ident[sizeof(struct hardware)];
 	if (!options[DHO_DHCP_CLIENT_IDENTIFIER]) {
-		size_t hwlen = MIN(ip->hw_address.hlen,
-		    sizeof(client_ident.haddr));
-		client_ident.htype = ip->hw_address.htype;
-		client_ident.hlen = hwlen;
-		memcpy(client_ident.haddr, ip->hw_address.haddr, hwlen);
+		int hwlen = (ip->hw_address.hlen < sizeof(client_ident)-1) ?
+				ip->hw_address.hlen : sizeof(client_ident)-1;
+		client_ident[0] = ip->hw_address.htype;
+		memcpy(&client_ident[1], ip->hw_address.haddr, hwlen);
 		options[DHO_DHCP_CLIENT_IDENTIFIER] = &option_elements[DHO_DHCP_CLIENT_IDENTIFIER];
-		options[DHO_DHCP_CLIENT_IDENTIFIER]->value = (void *)&client_ident;
-		hwlen += offsetof(struct hardware, haddr);
-		options[DHO_DHCP_CLIENT_IDENTIFIER]->len = hwlen;
-		options[DHO_DHCP_CLIENT_IDENTIFIER]->buf_size = hwlen;
+		options[DHO_DHCP_CLIENT_IDENTIFIER]->value = client_ident;
+		options[DHO_DHCP_CLIENT_IDENTIFIER]->len = hwlen+1;
+		options[DHO_DHCP_CLIENT_IDENTIFIER]->buf_size = hwlen+1;
 		options[DHO_DHCP_CLIENT_IDENTIFIER]->timeout = 0xFFFFFFFF;
 	}
 
@@ -1609,8 +1605,8 @@ make_discover(struct interface_info *ip,
 	    0, sizeof(ip->client->packet.siaddr));
 	memset(&(ip->client->packet.giaddr),
 	    0, sizeof(ip->client->packet.giaddr));
-	memcpy(ip->client->packet.chaddr, ip->hw_address.haddr,
-	    MIN(ip->hw_address.hlen, sizeof(ip->client->packet.chaddr)));
+	memcpy(ip->client->packet.chaddr,
+	    ip->hw_address.haddr, ip->hw_address.hlen);
 }
 
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201605182335.u4INZbv8075515>