From 647353d3e6621b32696a08d66656b7c6bb8fb0a3 Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Sat, 6 Feb 2021 11:52:37 +0100 Subject: [PATCH] buf_copy(): Fail if there's no data to write or nothing to do Prevents undefined behaviour "applying zero offset to null pointer". Reported by: Joshua Rogers (Opera) --- deanimate.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/deanimate.c b/deanimate.c index 494e6a85..b0f3f1f8 100644 --- a/deanimate.c +++ b/deanimate.c @@ -131,6 +131,14 @@ static int buf_extend(struct binbuffer *buf, size_t length) *********************************************************************/ static int buf_copy(struct binbuffer *src, struct binbuffer *dst, size_t length) { + /* + * Sanity check: Make sure the source buffer contains + * data and there's work to be done. + */ + if (src->buffer == NULL || src->size == 0 || length == 0) + { + return 1; + } /* * Sanity check: Can't copy more data than we have -- 2.39.2