]> granicus.if.org Git - python/commitdiff
Issue #12839: Fix crash in zlib module due to version mismatch.
authorNadeem Vawda <nadeem.vawda@gmail.com>
Sun, 28 Aug 2011 09:23:57 +0000 (11:23 +0200)
committerNadeem Vawda <nadeem.vawda@gmail.com>
Sun, 28 Aug 2011 09:23:57 +0000 (11:23 +0200)
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.

Misc/ACKS
Misc/NEWS
Modules/zlibmodule.c

index cdae287ddae29dd9c8b2fc446872c368789e93ed..e728c511e13bd30c4b7fc0f709c1aeba5e48108b 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -813,6 +813,7 @@ Monty Taylor
 Amy Taylor
 Anatoly Techtonik
 Mikhail Terekhov
+Richard M. Tew
 Tobias Thelen
 James Thomas
 Robin Thomas
index e7faa4e117de04248e19acb4a25bfff11d6aa2b2..3709142c8fed40eebc18938d4061d22e10b31f1a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -40,6 +40,9 @@ Core and Builtins
 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
   avoid them being inherited by other subprocesses.
 
index bd6d6e256bc919855079ef2cda7ee0794e66aa4e..035aa8e085da66b05ff5ca813a87be8be3117ad9 100644 (file)
@@ -72,7 +72,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: