]> git.lizzy.rs Git - zlib.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)
committerMark Adler <zlib@madler.net>
Fri, 13 Oct 2017 02:44:01 +0000 (19:44 -0700)
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 50cf4b4571cfec347ce5891b76fcb6675fcb580d..1321548c33f0d6e0c012d99558696c56bffb70b7 100644 (file)
--- a/trees.c
+++ b/trees.c
@@ -870,7 +870,8 @@ void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last)
     bi_windup(s);        /* align on byte boundary */
     put_short(s, (ush)stored_len);
     put_short(s, (ush)~stored_len);
-    zmemcpy(s->pending_buf + s->pending, (Bytef *)buf, stored_len);
+    if (stored_len)
+        zmemcpy(s->pending_buf + s->pending, (Bytef *)buf, stored_len);
     s->pending += stored_len;
 #ifdef ZLIB_DEBUG
     s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;