Commit 5514067b authored by Nadeem Vawda's avatar Nadeem Vawda

Issue #12839: Fix crash in zlib module due to version mismatch.

If the version of zlib used to compile the zlib module is incompatible
with the one that is actually linked in, then calls into zlib will fail.
This can leave attributes of the z_stream uninitialized, so we must take
care to avoid segfaulting by trying to use an invalid pointer.

Fix by Richard M. Tew.
parent 937a73a8
...@@ -813,6 +813,7 @@ Monty Taylor ...@@ -813,6 +813,7 @@ Monty Taylor
Amy Taylor Amy Taylor
Anatoly Techtonik Anatoly Techtonik
Mikhail Terekhov Mikhail Terekhov
Richard M. Tew
Tobias Thelen Tobias Thelen
James Thomas James Thomas
Robin Thomas Robin Thomas
......
...@@ -40,6 +40,9 @@ Core and Builtins ...@@ -40,6 +40,9 @@ Core and Builtins
Library Library
------- -------
- Issue #12839: Fix crash in zlib module due to version mismatch.
Fix by Richard M. Tew.
- Issue #12786: Set communication pipes used by subprocess.Popen CLOEXEC to - Issue #12786: Set communication pipes used by subprocess.Popen CLOEXEC to
avoid them being inherited by other subprocesses. avoid them being inherited by other subprocesses.
......
...@@ -72,7 +72,13 @@ typedef struct ...@@ -72,7 +72,13 @@ typedef struct
static void static void
zlib_error(z_stream zst, int err, char *msg) zlib_error(z_stream zst, int err, char *msg)
{ {
const char *zmsg = zst.msg; const char *zmsg = Z_NULL;
/* In case of a version mismatch, zst.msg won't be initialized.
Check for this case first, before looking at zst.msg. */
if (err == Z_VERSION_ERROR)
zmsg = "library version mismatch";
if (zmsg == Z_NULL)
zmsg = zst.msg;
if (zmsg == Z_NULL) { if (zmsg == Z_NULL) {
switch (err) { switch (err) {
case Z_BUF_ERROR: case Z_BUF_ERROR:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment