aboutsummaryrefslogtreecommitdiff
path: root/lib/libutil
diff options
context:
space:
mode:
authorPedro F. Giffuni <pfg@FreeBSD.org>2017-04-21 19:27:33 +0000
committerPedro F. Giffuni <pfg@FreeBSD.org>2017-04-21 19:27:33 +0000
commitefa8af7c73372cd2dc2cca734c2713592fd0d6bd (patch)
tree95b96b0ac6ded34ff5298c39db0a2c518884c3ca /lib/libutil
parent6284ff839866511366571b2529897756273a6398 (diff)
downloadsrc-efa8af7c73372cd2dc2cca734c2713592fd0d6bd.tar.gz
src-efa8af7c73372cd2dc2cca734c2713592fd0d6bd.zip
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
Notes
Notes: svn path=/head/; revision=317265
Diffstat (limited to 'lib/libutil')
-rw-r--r--lib/libutil/gr_util.c2
-rw-r--r--lib/libutil/login_cap.c2
-rw-r--r--lib/libutil/pw_util.c2
3 files changed, 3 insertions, 3 deletions
diff --git a/lib/libutil/gr_util.c b/lib/libutil/gr_util.c
index 99f268cf1833..fcc08209e0cc 100644
--- a/lib/libutil/gr_util.c
+++ b/lib/libutil/gr_util.c
@@ -205,7 +205,7 @@ gr_copy(int ffd, int tfd, const struct group *gr, struct group *old_gr)
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;
}
diff --git a/lib/libutil/login_cap.c b/lib/libutil/login_cap.c
index 9c8d4a689750..cea7630698af 100644
--- a/lib/libutil/login_cap.c
+++ b/lib/libutil/login_cap.c
@@ -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;
}
diff --git a/lib/libutil/pw_util.c b/lib/libutil/pw_util.c
index e55c2b1e2f12..85b8d04ba7ae 100644
--- a/lib/libutil/pw_util.c
+++ b/lib/libutil/pw_util.c
@@ -468,7 +468,7 @@ pw_copy(int ffd, int tfd, const struct passwd *pw, struct passwd *old_pw)
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;
}