]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Return an error if the gzputs string length can't fit in an int.
authorMark Adler <madler@alumni.caltech.edu>
Sun, 12 Feb 2017 07:54:17 +0000 (23:54 -0800)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Tue, 15 Jan 2019 09:56:40 +0000 (10:56 +0100)
gzwrite.c

index 66180913aef5bb0dc8bb6896aab6a247a9a53b0a..20e1d5c63fadabcfabbd8d1d837bbe465169e34b 100644 (file)
--- a/gzwrite.c
+++ b/gzwrite.c
@@ -320,8 +320,7 @@ int ZEXPORT PREFIX(gzputc)(gzFile file, int c) {
 
 /* -- see zlib.h -- */
 int ZEXPORT PREFIX(gzputs)(gzFile file, const char *s) {
-    int ret;
-    size_t len;
+    size_t len, put;
     gz_state *state;
 
     /* get internal structure */
@@ -335,8 +334,12 @@ int ZEXPORT PREFIX(gzputs)(gzFile file, const char *s) {
 
     /* write string */
     len = strlen(s);
-    ret = (int)gz_write(state, s, len);
-    return ret == 0 && len != 0 ? -1 : ret;
+    if ((int)len < 0 || (unsigned)len != len) {
+        gz_error(state, Z_STREAM_ERROR, "string length does not fit in int");
+        return -1;
+    }
+    put = gz_write(state, s, len);
+    return put < len ? -1 : (int)len;
 }
 
 /* -- see zlib.h -- */