From owner-svn-src-head@freebsd.org Wed May 31 21:31:16 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C2C96B950C7; Wed, 31 May 2017 21:31:16 +0000 (UTC) (envelope-from stevek@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 91A6A6A8D9; Wed, 31 May 2017 21:31:16 +0000 (UTC) (envelope-from stevek@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v4VLVFsv054266; Wed, 31 May 2017 21:31:15 GMT (envelope-from stevek@FreeBSD.org) Received: (from stevek@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v4VLVFnb054265; Wed, 31 May 2017 21:31:15 GMT (envelope-from stevek@FreeBSD.org) Message-Id: <201705312131.v4VLVFnb054265@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: stevek set sender to stevek@FreeBSD.org using -f From: "Stephen J. Kiernan" Date: Wed, 31 May 2017 21:31:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r319361 - head/sbin/dhclient X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 31 May 2017 21:31:16 -0000 Author: stevek Date: Wed May 31 21:31:15 2017 New Revision: 319361 URL: https://svnweb.freebsd.org/changeset/base/319361 Log: parse.c parse_string When parse_semi fails, free s before returning parse.c parse_numeric_aggregate The memory assigned to bufp is complicated, it can either be from the input parameter buf or allocated locally. Introduce a new variable lbufp to track when it is assigned locally and to free it when appropriate. Submitted by: Thomas Rix Reviewed by: jhb Approved by: sjg (mentor) Obtained from: Juniper Networks, Inc. MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D9899 Modified: head/sbin/dhclient/parse.c Modified: head/sbin/dhclient/parse.c ============================================================================== --- head/sbin/dhclient/parse.c Wed May 31 21:20:42 2017 (r319360) +++ head/sbin/dhclient/parse.c Wed May 31 21:31:15 2017 (r319361) @@ -131,8 +131,10 @@ parse_string(FILE *cfile) error("no memory for string %s.", val); memcpy(s, val, valsize); - if (!parse_semi(cfile)) + if (!parse_semi(cfile)) { + free(s); return (NULL); + } return (s); } @@ -246,9 +248,10 @@ parse_numeric_aggregate(FILE *cfile, unsigned char *bu char *val, *t; size_t valsize; pair c = NULL; + unsigned char *lbufp = NULL; if (!bufp && *max) { - bufp = malloc(*max * size / 8); + lbufp = bufp = malloc(*max * size / 8); if (!bufp) error("can't allocate space for numeric aggregate"); } else @@ -265,6 +268,7 @@ parse_numeric_aggregate(FILE *cfile, unsigned char *bu parse_warn("too few numbers."); if (token != SEMI) skip_to_semi(cfile); + free(lbufp); return (NULL); } token = next_token(&val, cfile); @@ -281,6 +285,7 @@ parse_numeric_aggregate(FILE *cfile, unsigned char *bu (base != 16 || token != NUMBER_OR_NAME)) { parse_warn("expecting numeric value."); skip_to_semi(cfile); + free(lbufp); return (NULL); } /* @@ -302,6 +307,7 @@ parse_numeric_aggregate(FILE *cfile, unsigned char *bu /* If we had to cons up a list, convert it now. */ if (c) { + free(lbufp); bufp = malloc(count * size / 8); if (!bufp) error("can't allocate space for numeric aggregate.");