From ff28e0d00dbf8c4f84bbb379aa87257ae31cdd9d Mon Sep 17 00:00:00 2001 From: Phil Turnbull Date: Wed, 5 Jul 2017 15:29:15 -0400 Subject: Avoid memcpy'ing NULL pointers A UBSAN warning can be triggered because the link title is an empty string: src/inlines.c:113:20: runtime error: null pointer passed as argument 2, which is declared to never be null which can be triggered by: ``` [f]:_ [f] ``` The length of the memcpy is zero so the NULL pointer is not dereferenced but it is still undefined behaviour. --- src/inlines.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/inlines.c') diff --git a/src/inlines.c b/src/inlines.c index f5b0621..b864e12 100644 --- a/src/inlines.c +++ b/src/inlines.c @@ -115,7 +115,8 @@ static cmark_chunk chunk_clone(cmark_mem *mem, cmark_chunk *src) { c.len = len; c.data = (unsigned char *)mem->calloc(len + 1, 1); c.alloc = 1; - memcpy(c.data, src->data, len); + if (len) + memcpy(c.data, src->data, len); c.data[len] = '\0'; return c; -- cgit v1.2.3