From 9f8961c4754dc9a1de486d6dabd41484fc6c54a8 Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Wed, 29 May 2019 12:14:28 -0600 Subject: [PATCH] mem: do not permit zero-sized allocations (FLU-01-002) note: security audit report by Cure53/CNCF Signed-off-by: Eduardo Silva --- include/fluent-bit/flb_mem.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/fluent-bit/flb_mem.h b/include/fluent-bit/flb_mem.h index 7c62d850431..8022a7f16f5 100644 --- a/include/fluent-bit/flb_mem.h +++ b/include/fluent-bit/flb_mem.h @@ -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; @@ -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; @@ -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;