From owner-svn-src-all@FreeBSD.ORG Mon Jun 15 07:24:17 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 80779106566B; Mon, 15 Jun 2009 07:24:17 +0000 (UTC) (envelope-from brian@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 534E28FC08; Mon, 15 Jun 2009 07:24:17 +0000 (UTC) (envelope-from brian@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n5F7OH4F082659; Mon, 15 Jun 2009 07:24:17 GMT (envelope-from brian@svn.freebsd.org) Received: (from brian@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n5F7OHtp082658; Mon, 15 Jun 2009 07:24:17 GMT (envelope-from brian@svn.freebsd.org) Message-Id: <200906150724.n5F7OHtp082658@svn.freebsd.org> From: Brian Somers Date: Mon, 15 Jun 2009 07:24:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r194235 - stable/7/sbin/dhclient X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Jun 2009 07:24:18 -0000 Author: brian Date: Mon Jun 15 07:24:16 2009 New Revision: 194235 URL: http://svn.freebsd.org/changeset/base/194235 Log: MFC: r193765: Fix an off by one error when we limit append/prepend text sizes based on our internal buffer sizes. When we 'append', assume we're appending to text. Some MS dhcp servers will give us a string with the length including the trailing NUL. when we 'append domain-name', we get something like "search x.y\000 z" in resolv.conf :( Modified: stable/7/sbin/dhclient/ (props changed) stable/7/sbin/dhclient/dhclient.c Modified: stable/7/sbin/dhclient/dhclient.c ============================================================================== --- stable/7/sbin/dhclient/dhclient.c Mon Jun 15 07:17:55 2009 (r194234) +++ stable/7/sbin/dhclient/dhclient.c Mon Jun 15 07:24:16 2009 (r194235) @@ -1977,7 +1977,7 @@ supersede: len = ip->client-> config->defaults[i].len + lease->options[i].len; - if (len > sizeof(dbuf)) { + if (len >= sizeof(dbuf)) { warning("no space to %s %s", "prepend option", dhcp_options[i].name); @@ -1996,24 +1996,34 @@ supersede: dp[len] = '\0'; break; case ACTION_APPEND: + /* + * When we append, we assume that we're + * appending to text. Some MS servers + * include a NUL byte at the end of + * the search string provided. + */ len = ip->client-> config->defaults[i].len + lease->options[i].len; - if (len > sizeof(dbuf)) { + if (len >= sizeof(dbuf)) { warning("no space to %s %s", "append option", dhcp_options[i].name); goto supersede; } - dp = dbuf; - memcpy(dp, + memcpy(dbuf, lease->options[i].data, lease->options[i].len); - memcpy(dp + lease->options[i].len, + for (dp = dbuf + lease->options[i].len; + dp > dbuf; dp--, len--) + if (dp[-1] != '\0') + break; + memcpy(dp, ip->client-> config->defaults[i].data, ip->client-> config->defaults[i].len); + dp = dbuf; dp[len] = '\0'; } } else {