From: Fabian Keil Date: Sat, 6 Feb 2021 10:52:37 +0000 (+0100) Subject: buf_copy(): Fail if there's no data to write or nothing to do X-Git-Tag: v_3_0_32~33 X-Git-Url: http://www.privoxy.org/gitweb/?a=commitdiff_plain;h=647353d3e6621b32696a08d66656b7c6bb8fb0a3;p=privoxy.git 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) --- 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