From owner-svn-src-head@freebsd.org Fri May 26 03:27:07 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 995ABD82137; Fri, 26 May 2017 03:27:07 +0000 (UTC) (envelope-from araujo@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 6984E1483; Fri, 26 May 2017 03:27:07 +0000 (UTC) (envelope-from araujo@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v4Q3R6qo078366; Fri, 26 May 2017 03:27:06 GMT (envelope-from araujo@FreeBSD.org) Received: (from araujo@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v4Q3R6Uw078365; Fri, 26 May 2017 03:27:06 GMT (envelope-from araujo@FreeBSD.org) Message-Id: <201705260327.v4Q3R6Uw078365@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: araujo set sender to araujo@FreeBSD.org using -f From: Marcelo Araujo Date: Fri, 26 May 2017 03:27:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r318915 - head/usr.sbin/ypldap 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: Fri, 26 May 2017 03:27:07 -0000 Author: araujo Date: Fri May 26 03:27:06 2017 New Revision: 318915 URL: https://svnweb.freebsd.org/changeset/base/318915 Log: Simplify parseval() by allocating a buffer the size of the input string, which will always be big enough to hold the output string. Obtained from: OpenBSD (revision 1.36) Modified: head/usr.sbin/ypldap/aldap.c Modified: head/usr.sbin/ypldap/aldap.c ============================================================================== --- head/usr.sbin/ypldap/aldap.c Fri May 26 02:30:26 2017 (r318914) +++ head/usr.sbin/ypldap/aldap.c Fri May 26 03:27:06 2017 (r318915) @@ -1212,30 +1212,19 @@ char * parseval(char *p, size_t len) { char hex[3]; - char *cp = p, *buffer, *newbuffer; - size_t size, newsize, i, j; + char *buffer; + size_t i, j; - size = 50; - if ((buffer = calloc(1, size)) == NULL) + if ((buffer = calloc(1, len + 1)) == NULL) return NULL; for (i = j = 0; j < len; i++) { - if (i >= size) { - newsize = size + 1024; - if ((newbuffer = realloc(buffer, newsize)) == NULL) { - free(buffer); - return (NULL); - } - buffer = newbuffer; - size = newsize; - } - - if (cp[j] == '\\') { - strlcpy(hex, cp + j + 1, sizeof(hex)); + if (p[j] == '\\') { + strlcpy(hex, p + j + 1, sizeof(hex)); buffer[i] = (char)strtoumax(hex, NULL, 16); j += 3; } else { - buffer[i] = cp[j]; + buffer[i] = p[j]; j++; } }