mirror of
https://github.com/systemd/systemd.git
synced 2024-11-06 16:59:03 +03:00
alloca: add an overflow check too
Of course, alloca() shouldn't be used with anything that can grow without bounds anyway, but let's better safe than sorry, and catch this early. Since alloca() is not supposed to return an error we trigger an assert() instead, which is still better than heap trickery.
This commit is contained in:
parent
da6053d0a7
commit
1232c44718
@ -18,9 +18,17 @@
|
||||
|
||||
#define new0(t, n) ((t*) calloc((n), sizeof(t)))
|
||||
|
||||
#define newa(t, n) ((t*) alloca(sizeof(t)*(n)))
|
||||
#define newa(t, n) \
|
||||
({ \
|
||||
assert(!size_multiply_overflow(sizeof(t), n)); \
|
||||
(t*) alloca(sizeof(t)*(n)); \
|
||||
})
|
||||
|
||||
#define newa0(t, n) ((t*) alloca0(sizeof(t)*(n)))
|
||||
#define newa0(t, n) \
|
||||
({ \
|
||||
assert(!size_multiply_overflow(sizeof(t), n)); \
|
||||
(t*) alloca0(sizeof(t)*(n)); \
|
||||
})
|
||||
|
||||
#define newdup(t, p, n) ((t*) memdup_multiply(p, sizeof(t), (n)))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user