Skip to content

Commit

Permalink
mem: do not permit zero-sized allocations (FLU-01-002)
Browse files Browse the repository at this point in the history
note: security audit report by Cure53/CNCF

Signed-off-by: Eduardo Silva <[email protected]>
  • Loading branch information
edsiper committed May 30, 2019
1 parent 0806307 commit 9f8961c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions include/fluent-bit/flb_mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ static inline ALLOCSZ_ATTR(1)
void *flb_malloc(const size_t size) {
void *aux;

if (size == 0) {
return NULL;
}

aux = malloc(size);
if (flb_unlikely(!aux && size)) {
return NULL;
Expand All @@ -67,6 +71,10 @@ static inline ALLOCSZ_ATTR(1)
void *flb_calloc(size_t n, const size_t size) {
void *buf;

if (size == 0) {
return NULL;
}

buf = calloc(n, size);
if (flb_unlikely(!buf)) {
return NULL;
Expand All @@ -80,6 +88,13 @@ void *flb_realloc(void *ptr, const size_t size)
{
void *aux;

if (size == 0) {
if (ptr) {
free(ptr);
}
return NULL;
}

aux = realloc(ptr, size);
if (flb_unlikely(!aux && size)) {
return NULL;
Expand Down

0 comments on commit 9f8961c

Please sign in to comment.