]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Avoid an undefined behavior of memcpy() in _tr_stored_block().
authorMark Adler <zlib@madler.net>
Fri, 13 Oct 2017 02:44:01 +0000 (19:44 -0700)
committerMika Lindqvist <postmaster@raasu.org>
Fri, 13 Oct 2017 08:03:16 +0000 (11:03 +0300)
Allegedly the behavior of memcpy() is undefined if the source
pointer is NULL, even if the number of bytes to copy is zero.

trees.c

diff --git a/trees.c b/trees.c
index 6a7ba93d258d47ff34d8c1af757fd270ef8f176e..eedfdf02acafbc53dc95fedf83edb20295042c15 100644 (file)
--- 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;