From 1234cbbb41b6bf57c7094a5e9d015db7b303c44c Mon Sep 17 00:00:00 2001 From: "Pedro F. Giffuni" Date: Fri, 21 Apr 2017 19:27:33 +0000 Subject: 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 --- libutil/gr_util.c | 2 +- libutil/login_cap.c | 2 +- libutil/pw_util.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'libutil') diff --git a/libutil/gr_util.c b/libutil/gr_util.c index 99f268c..fcc0820 100644 --- a/libutil/gr_util.c +++ b/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/libutil/login_cap.c b/libutil/login_cap.c index 9c8d4a6..cea7630 100644 --- a/libutil/login_cap.c +++ b/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/libutil/pw_util.c b/libutil/pw_util.c index e55c2b1..85b8d04 100644 --- a/libutil/pw_util.c +++ b/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; } -- cgit v1.2.3-56-ge451