mirror of
https://github.com/clearlinux/systemd-stable.git
synced 2026-09-04 04:31:27 +00:00
util: check for overflow in greedy_realloc()
(cherry picked from commit 98088803bb)
Conflicts:
src/shared/util.c
This commit is contained in:
committed by
Colin Guthrie
parent
f980d7eccb
commit
f0c730c540
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user