From owner-svn-src-head@freebsd.org Fri Apr 21 19:27:35 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 9957FD498B1; Fri, 21 Apr 2017 19:27:35 +0000 (UTC) (envelope-from pfg@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 74A20177; Fri, 21 Apr 2017 19:27:35 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v3LJRYOO058187; Fri, 21 Apr 2017 19:27:34 GMT (envelope-from pfg@FreeBSD.org) Received: (from pfg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v3LJRYHj058182; Fri, 21 Apr 2017 19:27:34 GMT (envelope-from pfg@FreeBSD.org) Message-Id: <201704211927.v3LJRYHj058182@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pfg set sender to pfg@FreeBSD.org using -f From: "Pedro F. Giffuni" Date: Fri, 21 Apr 2017 19:27:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r317265 - in head/lib: libgssapi libiconv_modules/ISO2022 libutil 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, 21 Apr 2017 19:27:35 -0000 Author: pfg Date: Fri Apr 21 19:27:33 2017 New Revision: 317265 URL: https://svnweb.freebsd.org/changeset/base/317265 Log: lib: initial use of reallocarray(3). Make some use of reallocarray, attempting to limit it to cases where the parameters are unsigned and there is some theoretical chance of overflow. MFC afer: 2 weeks Differential Revision: https://reviews.freebsd.org/D9980 Modified: head/lib/libgssapi/gss_buffer_set.c head/lib/libiconv_modules/ISO2022/citrus_iso2022.c head/lib/libutil/gr_util.c head/lib/libutil/login_cap.c head/lib/libutil/pw_util.c Modified: head/lib/libgssapi/gss_buffer_set.c ============================================================================== --- head/lib/libgssapi/gss_buffer_set.c Fri Apr 21 17:57:23 2017 (r317264) +++ head/lib/libgssapi/gss_buffer_set.c Fri Apr 21 19:27:33 2017 (r317265) @@ -76,8 +76,8 @@ gss_add_buffer_set_member(OM_uint32 * mi } set = *buffer_set; - set->elements = realloc(set->elements, - (set->count + 1) * sizeof(set->elements[0])); + set->elements = reallocarray(set->elements, set->count + 1, + sizeof(set->elements[0])); if (set->elements == NULL) { *minor_status = ENOMEM; return (GSS_S_FAILURE); Modified: head/lib/libiconv_modules/ISO2022/citrus_iso2022.c ============================================================================== --- head/lib/libiconv_modules/ISO2022/citrus_iso2022.c Fri Apr 21 17:57:23 2017 (r317264) +++ head/lib/libiconv_modules/ISO2022/citrus_iso2022.c Fri Apr 21 19:27:33 2017 (r317265) @@ -259,8 +259,8 @@ get_recommend(_ISO2022EncodingInfo * __r if (!ei->recommend[i]) ei->recommend[i] = malloc(sizeof(_ISO2022Charset)); else { - p = realloc(ei->recommend[i], - sizeof(_ISO2022Charset) * (ei->recommendsize[i] + 1)); + p = reallocarray(ei->recommend[i], ei->recommendsize[i] + 1, + sizeof(_ISO2022Charset)); if (!p) return (_PARSEFAIL); ei->recommend[i] = p; Modified: head/lib/libutil/gr_util.c ============================================================================== --- head/lib/libutil/gr_util.c Fri Apr 21 17:57:23 2017 (r317264) +++ head/lib/libutil/gr_util.c Fri Apr 21 19:27:33 2017 (r317265) @@ -205,7 +205,7 @@ gr_copy(int ffd, int tfd, const struct g if (eof) break; while ((size_t)(q - p) >= size) { - if ((tmp = realloc(buf, size * 2)) == NULL) { + if ((tmp = reallocarray(buf, 2, size)) == NULL) { warnx("group line too long"); goto err; } Modified: head/lib/libutil/login_cap.c ============================================================================== --- head/lib/libutil/login_cap.c Fri Apr 21 17:57:23 2017 (r317264) +++ head/lib/libutil/login_cap.c Fri Apr 21 19:27:33 2017 (r317265) @@ -86,7 +86,7 @@ allocarray(size_t sz) if (sz <= internal_arraysz) p = internal_array; - else if ((p = realloc(internal_array, sz * sizeof(char*))) != NULL) { + else if ((p = reallocarray(internal_array, sz, sizeof(char*))) != NULL) { internal_arraysz = sz; internal_array = p; } Modified: head/lib/libutil/pw_util.c ============================================================================== --- head/lib/libutil/pw_util.c Fri Apr 21 17:57:23 2017 (r317264) +++ head/lib/libutil/pw_util.c Fri Apr 21 19:27:33 2017 (r317265) @@ -468,7 +468,7 @@ pw_copy(int ffd, int tfd, const struct p if (eof) break; while ((size_t)(q - p) >= size) { - if ((tmp = realloc(buf, size * 2)) == NULL) { + if ((tmp = reallocarray(buf, 2, size)) == NULL) { warnx("passwd line too long"); goto err; }