projects
/
systemd
/
.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
e5e21a0
)
alloc-util: add extra overflow checks to GREEDY_REALLOC()
author
Lennart Poettering
<lennart@poettering.net>
Wed, 20 Mar 2019 09:31:13 +0000
(10:31 +0100)
committer
Lennart Poettering
<lennart@poettering.net>
Wed, 20 Mar 2019 09:48:33 +0000
(10:48 +0100)
src/basic/alloc-util.c
patch
|
blob
|
history
diff --git
a/src/basic/alloc-util.c
b/src/basic/alloc-util.c
index 15b67665d260e8b29d4d7989bc3520b57df712b9..f4bd33f4e014246a9c9e68f8f75e0023541a967d 100644
(file)
--- a/
src/basic/alloc-util.c
+++ b/
src/basic/alloc-util.c
@@
-48,13
+48,17
@@
void* greedy_realloc(void **p, size_t *allocated, size_t need, size_t size) {
if (*allocated >= need)
return *p;
- newalloc = MAX(need * 2, 64u / size);
-
a = newalloc * size
;
+ if (_unlikely_(need > SIZE_MAX/2)) /* Overflow check */
+
return NULL
;
- /* check for overflows */
- if (
a < size * need
)
+ newalloc = need * 2;
+ if (
size_multiply_overflow(newalloc, size)
)
return NULL;
+ a = newalloc * size;
+ if (a < 64) /* Allocate at least 64 bytes */
+ a = 64;
+
q = realloc(*p, a);
if (!q)
return NULL;