44 lines
1.2 KiB
Diff
44 lines
1.2 KiB
Diff
From 90287635ef9ae8e51e120483d1b48789239a0577 Mon Sep 17 00:00:00 2001
|
|
From: Mark Adler <madler@alumni.caltech.edu>
|
|
Date: Sat, 11 Feb 2017 23:54:17 -0800
|
|
Subject: [PATCH] Return an error if the gzputs string length can't fit in an int.
|
|
|
|
Reference:https://github.com/madler/zlib/commit/90287635ef9ae8e51e120483d1b48789239a0577
|
|
Conflict:NA
|
|
---
|
|
gzwrite.c | 11 +++++++----
|
|
1 file changed, 7 insertions(+), 4 deletions(-)
|
|
|
|
diff --git a/gzwrite.c b/gzwrite.c
|
|
index 35b9aa6..3560193 100644
|
|
--- a/gzwrite.c
|
|
+++ b/gzwrite.c
|
|
@@ -353,8 +353,7 @@ int ZEXPORT gzputs(file, str)
|
|
gzFile file;
|
|
const char *str;
|
|
{
|
|
- int ret;
|
|
- z_size_t len;
|
|
+ z_size_t len, put;
|
|
gz_statep state;
|
|
|
|
/* get internal structure */
|
|
@@ -368,8 +367,12 @@ int ZEXPORT gzputs(file, str)
|
|
|
|
/* write string */
|
|
len = strlen(str);
|
|
- ret = gz_write(state, str, 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, str, len);
|
|
+ return put < len ? -1 : (int)len;
|
|
}
|
|
|
|
#if defined(STDC) || defined(Z_HAVE_STDARG_H)
|
|
--
|
|
2.23.0
|
|
|