diff options
author | pfg <pfg@FreeBSD.org> | 2017-05-09 23:31:09 +0000 |
---|---|---|
committer | pfg <pfg@FreeBSD.org> | 2017-05-09 23:31:09 +0000 |
commit | 9498b1d27a47f26ccd6e4233ad479503fc73c207 (patch) | |
tree | 74b09547df77f0a50b0162e21daab37fb0bc1ed5 | |
parent | 643d95272bd8bc6a4fd1c99b1e560e28ea4f57c7 (diff) | |
download | FreeBSD-src-9498b1d27a47f26ccd6e4233ad479503fc73c207.zip FreeBSD-src-9498b1d27a47f26ccd6e4233ad479503fc73c207.tar.gz |
MFC r317265:
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.
-rw-r--r-- | lib/libgssapi/gss_buffer_set.c | 4 | ||||
-rw-r--r-- | lib/libiconv_modules/ISO2022/citrus_iso2022.c | 4 | ||||
-rw-r--r-- | lib/libutil/gr_util.c | 2 | ||||
-rw-r--r-- | lib/libutil/login_cap.c | 2 | ||||
-rw-r--r-- | lib/libutil/pw_util.c | 2 |
5 files changed, 7 insertions, 7 deletions
diff --git a/lib/libgssapi/gss_buffer_set.c b/lib/libgssapi/gss_buffer_set.c index af62e5c..100dd4d 100644 --- a/lib/libgssapi/gss_buffer_set.c +++ b/lib/libgssapi/gss_buffer_set.c @@ -76,8 +76,8 @@ gss_add_buffer_set_member(OM_uint32 * minor_status, } 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); diff --git a/lib/libiconv_modules/ISO2022/citrus_iso2022.c b/lib/libiconv_modules/ISO2022/citrus_iso2022.c index f3613d6..c88a23e 100644 --- a/lib/libiconv_modules/ISO2022/citrus_iso2022.c +++ b/lib/libiconv_modules/ISO2022/citrus_iso2022.c @@ -259,8 +259,8 @@ get_recommend(_ISO2022EncodingInfo * __restrict ei, 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; diff --git a/lib/libutil/gr_util.c b/lib/libutil/gr_util.c index 99f268c..fcc0820 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 9c8d4a6..cea7630 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 0c34e67..627d79b 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; } |