mirror of
https://github.com/systemd/systemd.git
synced 2026-08-08 00:51:19 +00:00
util: check for overflow in greedy_realloc()
This commit is contained in:
Notes:
Lennart Poettering
2014-02-17 22:48:22 +01:00
Backport: bugfix
@@ -5792,12 +5792,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;
|
||||
@@ -5808,9 +5814,14 @@ void* greedy_realloc(void **p, size_t *allocated, size_t need) {
|
||||
}
|
||||
|
||||
void* greedy_realloc0(void **p, size_t *allocated, size_t need) {
|
||||
size_t prev = *allocated;
|
||||
size_t prev;
|
||||
uint8_t *q;
|
||||
|
||||
assert(p);
|
||||
assert(allocated);
|
||||
|
||||
prev = *allocated;
|
||||
|
||||
q = greedy_realloc(p, allocated, need);
|
||||
if (!q)
|
||||
return NULL;
|
||||
|
||||
Reference in New Issue
Block a user