summaryrefslogtreecommitdiffstats
path: root/generic/tclZlib.c
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2017-04-27 10:51:50 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2017-04-27 10:51:50 (GMT)
commit08266ba63bcae218ba1c574d6128462468670b80 (patch)
treec79464525a30e9ec7b22e50b073abb23b716c405 /generic/tclZlib.c
parent90fde58143eea5e3f626221a006cf6ac3e398ebe (diff)
parentada887f2ef7727135a81639bc1fd6513ef6c8f43 (diff)
downloadtcl-08266ba63bcae218ba1c574d6128462468670b80.zip
tcl-08266ba63bcae218ba1c574d6128462468670b80.tar.gz
tcl-08266ba63bcae218ba1c574d6128462468670b80.tar.bz2
[50750c735a] Fix broken test and stop reading uninit-but-allocated memory in zlib channel transform.
Diffstat (limited to 'generic/tclZlib.c')
-rw-r--r--generic/tclZlib.c34
1 files changed, 16 insertions, 18 deletions
diff --git a/generic/tclZlib.c b/generic/tclZlib.c
index 96b8318..33eebd1 100644
--- a/generic/tclZlib.c
+++ b/generic/tclZlib.c
@@ -3113,30 +3113,28 @@ ZlibTransformOutput(
errorCodePtr);
}
+ /*
+ * No zero-length writes. Flushes must be explicit.
+ */
+
+ if (toWrite == 0) {
+ return 0;
+ }
+
cd->outStream.next_in = (Bytef *) buf;
cd->outStream.avail_in = toWrite;
- do {
+ while (cd->outStream.avail_in > 0) {
e = Deflate(&cd->outStream, cd->outBuffer, cd->outAllocated,
Z_NO_FLUSH, &produced);
+ if (e != Z_OK || produced == 0) {
+ break;
+ }
- if ((e == Z_OK && produced > 0) || e == Z_BUF_ERROR) {
- /*
- * deflate() indicates that it is out of space by returning
- * Z_BUF_ERROR *or* by simply returning Z_OK with no remaining
- * space; in either case, we must write the whole buffer out and
- * retry to compress what is left.
- */
-
- if (e == Z_BUF_ERROR) {
- produced = cd->outAllocated;
- e = Z_OK;
- }
- if (Tcl_WriteRaw(cd->parent, cd->outBuffer, produced) < 0) {
- *errorCodePtr = Tcl_GetErrno();
- return -1;
- }
+ if (Tcl_WriteRaw(cd->parent, cd->outBuffer, produced) < 0) {
+ *errorCodePtr = Tcl_GetErrno();
+ return -1;
}
- } while (e == Z_OK && produced > 0 && cd->outStream.avail_in > 0);
+ }
if (e == Z_OK) {
return toWrite - cd->outStream.avail_in;