Let's test for size and alignment in memalign to catch invalid input data. Also we need to test for NULL after calling the memalign function of the registered alloc operations. Signed-off-by: Janosch Frank <frankja@xxxxxxxxxxxxx> --- lib/alloc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/alloc.c b/lib/alloc.c index ecdbbc4..b763c70 100644 --- a/lib/alloc.c +++ b/lib/alloc.c @@ -47,6 +47,8 @@ void *memalign(size_t alignment, size_t size) uintptr_t mem; assert(alloc_ops && alloc_ops->memalign); + if (!size || !alignment) + return NULL; if (alignment <= sizeof(uintptr_t)) alignment = sizeof(uintptr_t); else @@ -55,6 +57,7 @@ void *memalign(size_t alignment, size_t size) blkalign = MAX(alignment, alloc_ops->align_min); size = ALIGN(size + METADATA_EXTRA, alloc_ops->align_min); p = alloc_ops->memalign(blkalign, size); + assert(p); /* Leave room for metadata before aligning the result. */ mem = (uintptr_t)p + METADATA_EXTRA; -- 2.20.1