From: Mark Adler Date: Fri, 13 Oct 2017 02:44:01 +0000 (-0700) Subject: Avoid an undefined behavior of memcpy() in _tr_stored_block(). X-Git-Tag: 1.9.9-b1~656^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=17a4df5a5e66fc89034115d0af37181881570b8e;p=thirdparty%2Fzlib-ng.git Avoid an undefined behavior of memcpy() in _tr_stored_block(). Allegedly the behavior of memcpy() is undefined if the source pointer is NULL, even if the number of bytes to copy is zero. --- diff --git a/trees.c b/trees.c index 6a7ba93d2..eedfdf02a 100644 --- a/trees.c +++ b/trees.c @@ -796,7 +796,8 @@ void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, char *buf, unsigned long s bi_windup(s); /* align on byte boundary */ put_short(s, (uint16_t)stored_len); put_short(s, (uint16_t)~stored_len); - memcpy(s->pending_buf + s->pending, (unsigned char *)buf, stored_len); + if (stored_len) + memcpy(s->pending_buf + s->pending, (unsigned char *)buf, stored_len); s->pending += stored_len; #ifdef ZLIB_DEBUG s->compressed_len = (s->compressed_len + 3 + 7) & (unsigned long)~7L;