]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: p_strarray_dup() - Harden against integer overflows
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 21 Apr 2026 20:14:04 +0000 (20:14 +0000)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Sat, 2 May 2026 05:30:11 +0000 (05:30 +0000)
src/lib/strfuncs.c

index 7ff107101800a7afebf759f86e87c43215c05fad..134313b696163f4a6dbd8ac7925ebc7d94f5841b 100644 (file)
@@ -954,9 +954,10 @@ const char **p_strarray_dup(pool_t pool, const char *const *arr)
        char *p;
        size_t len, size = sizeof(const char *);
 
-       /* @UNSAFE: integer overflow checks are missing */
-       for (i = 0; arr[i] != NULL; i++)
-               size += sizeof(const char *) + strlen(arr[i]) + 1;
+       for (i = 0; arr[i] != NULL; i++) {
+               size = MALLOC_ADD3(size, sizeof(const char *) + 1,
+                                  strlen(arr[i]));
+       }
 
        ret = p_malloc(pool, size);
        p = PTR_OFFSET(ret, sizeof(const char *) * (i + 1));