diff options
author | Mark Adler <madler@alumni.caltech.edu> | 2017-02-11 23:54:17 -0800 |
---|---|---|
committer | Mark Adler <madler@alumni.caltech.edu> | 2017-02-15 22:39:26 -0800 |
commit | 90287635ef9ae8e51e120483d1b48789239a0577 (patch) | |
tree | e38f2db85fa0c9d07eca99d8a244ccfae37b53b6 /gzwrite.c | |
parent | 60a5ecc62b18d1e2391993b1fcfc10e100720642 (diff) | |
download | zlib-90287635ef9ae8e51e120483d1b48789239a0577.tar.gz zlib-90287635ef9ae8e51e120483d1b48789239a0577.tar.bz2 zlib-90287635ef9ae8e51e120483d1b48789239a0577.zip |
Return an error if the gzputs string length can't fit in an int.
Diffstat (limited to 'gzwrite.c')
-rw-r--r-- | gzwrite.c | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -353,8 +353,7 @@ int ZEXPORT gzputs(file, str) | |||
353 | gzFile file; | 353 | gzFile file; |
354 | const char *str; | 354 | const char *str; |
355 | { | 355 | { |
356 | int ret; | 356 | z_size_t len, put; |
357 | z_size_t len; | ||
358 | gz_statep state; | 357 | gz_statep state; |
359 | 358 | ||
360 | /* get internal structure */ | 359 | /* get internal structure */ |
@@ -368,8 +367,12 @@ int ZEXPORT gzputs(file, str) | |||
368 | 367 | ||
369 | /* write string */ | 368 | /* write string */ |
370 | len = strlen(str); | 369 | len = strlen(str); |
371 | ret = gz_write(state, str, len); | 370 | if ((int)len < 0 || (unsigned)len != len) { |
372 | return ret == 0 && len != 0 ? -1 : ret; | 371 | gz_error(state, Z_STREAM_ERROR, "string length does not fit in int"); |
372 | return -1; | ||
373 | } | ||
374 | put = gz_write(state, str, len); | ||
375 | return put < len ? -1 : (int)len; | ||
373 | } | 376 | } |
374 | 377 | ||
375 | #if defined(STDC) || defined(Z_HAVE_STDARG_H) | 378 | #if defined(STDC) || defined(Z_HAVE_STDARG_H) |