]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #12839: Fix crash in zlib module due to version mismatch.
authorNadeem Vawda <nadeem.vawda@gmail.com>
Sun, 28 Aug 2011 09:26:46 +0000 (11:26 +0200)
committerNadeem Vawda <nadeem.vawda@gmail.com>
Sun, 28 Aug 2011 09:26:46 +0000 (11:26 +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 d345e54ef9d16f3f06f286bcd8d5ce4b05c22f62..add8c617a7ff95dab8d1e1fedee83def7c7bf3b3 100644 (file)
--- 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
index 48ef326d56e378a53eb850dedfb4fcdea00d4d48..86eea69a3f6144300771afa03c8d79e18c5efb8e 100644 (file)
--- 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?
 ===============================================
index ba0e59ce0641d2ab6d3154b9b611b89d76aa8eef..a1e605b3d2be391f3c9a80e1e28fa03a767a180a 100644 (file)
@@ -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: