]> git.cameronkatri.com Git - pw-darwin.git/commitdiff
lib: initial use of reallocarray(3).
authorPedro F. Giffuni <pfg@FreeBSD.org>
Fri, 21 Apr 2017 19:27:33 +0000 (19:27 +0000)
committerPedro F. Giffuni <pfg@FreeBSD.org>
Fri, 21 Apr 2017 19:27:33 +0000 (19:27 +0000)
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
libutil/login_cap.c
libutil/pw_util.c

index 99f268cf1833a6fc2a79fdb33232cbbdcb62d5c9..fcc08209e0cc4df85ed5f2d9096ec266b086785a 100644 (file)
@@ -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;
                                }
index 9c8d4a689750c078e728316ca3fea805d641bbbb..cea7630698af708063f6ef1b01e36a73a2abd610 100644 (file)
@@ -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;
     }
index e55c2b1e2f123e22cec919bc237709ef5396c21a..85b8d04ba7ae3699e0672eeacca498fbd551e4f1 100644 (file)
@@ -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;
                                }