Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 21 Apr 2017 19:27:34 +0000 (UTC)
From:      "Pedro F. Giffuni" <pfg@FreeBSD.org>
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
Message-ID:  <201704211927.v3LJRYHj058182@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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;
 				}



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