[Python-checkins] cpython (merge 3.2 -> default): Merge: #12839: Fix crash in zlib module due to version mismatch.

nadeem.vawda python-checkins at python.org
Sun Aug 28 11:30:04 CEST 2011


http://hg.python.org/cpython/rev/b384231df332
changeset:   72112:b384231df332
parent:      72109:1cd334b92064
parent:      72111:cc9e794bf94f
user:        Nadeem Vawda <nadeem.vawda at gmail.com>
date:        Sun Aug 28 11:29:35 2011 +0200
summary:
  Merge: #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.

files:
  Misc/ACKS            |  1 +
  Misc/NEWS            |  3 +++
  Modules/zlibmodule.c |  8 +++++++-
  3 files changed, 11 insertions(+), 1 deletions(-)


diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -933,6 +933,7 @@
 Amy Taylor
 Anatoly Techtonik
 Mikhail Terekhov
+Richard M. Tew
 Tobias Thelen
 James Thomas
 Robin Thomas
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -268,6 +268,9 @@
 Library
 -------
 
+- Issue #12839: Fix crash in zlib module due to version mismatch.
+  Fix by Richard M. Tew.
+
 - Issue #9923: The mailcap module now correctly uses the platform path
   separator for the MAILCAP environment variable on non-POSIX platforms.
 
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c
--- a/Modules/zlibmodule.c
+++ b/Modules/zlibmodule.c
@@ -53,7 +53,13 @@
 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:

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list