summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNadeem Vawda <nadeem.vawda@gmail.com>2011-08-28 09:26:46 (GMT)
committerNadeem Vawda <nadeem.vawda@gmail.com>2011-08-28 09:26:46 (GMT)
commit97d67924e3a3ac1bbe07d6abc02c233a330013f1 (patch)
tree0b4a9ccea44ce886d91b60ae5cc26dfe41745b97
parent0c97e5f36aa59e0221b9d279dfea83ff6f7936c0 (diff)
downloadcpython-97d67924e3a3ac1bbe07d6abc02c233a330013f1.zip
cpython-97d67924e3a3ac1bbe07d6abc02c233a330013f1.tar.gz
cpython-97d67924e3a3ac1bbe07d6abc02c233a330013f1.tar.bz2
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.
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS4
-rw-r--r--Modules/zlibmodule.c8
3 files changed, 12 insertions, 1 deletions
diff --git a/Misc/ACKS b/Misc/ACKS
index d345e54..add8c61 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -873,6 +873,7 @@ Monty Taylor
Amy Taylor
Anatoly Techtonik
Mikhail Terekhov
+Richard M. Tew
Tobias Thelen
James Thomas
Robin Thomas
diff --git a/Misc/NEWS b/Misc/NEWS
index 48ef326..86eea69 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -17,6 +17,10 @@ Core and Builtins
Library
-------
+- Issue #12839: Fix crash in zlib module due to version mismatch.
+ Fix by Richard M. Tew.
+
+
What's New in Python 3.2.2 release candidate 1?
===============================================
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c
index ba0e59c..a1e605b 100644
--- a/Modules/zlibmodule.c
+++ b/Modules/zlibmodule.c
@@ -52,7 +52,13 @@ typedef struct
static void
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) {
switch (err) {
case Z_BUF_ERROR: