util: check for overflow in greedy_realloc()

(cherry picked from commit 98088803bb)

Conflicts:
	src/shared/util.c
This commit is contained in:
Lennart Poettering
2014-02-23 12:41:54 +00:00
committed by Colin Guthrie
parent f980d7eccb
commit f0c730c540
+8
View File
@@ -5832,10 +5832,18 @@ void* greedy_realloc(void **p, size_t *allocated, size_t need) {
size_t a;
void *q;
assert(p);
assert(allocated);
if (*allocated >= need)
return *p;
a = MAX(64u, need * 2);
/* check for overflows */
if (a < need)
return NULL;
q = realloc(*p, a);
if (!q)
return NULL;