diff options
| author | Nadeem Vawda <nadeem.vawda@gmail.com> | 2011-08-28 11:29:35 +0200 |
|---|---|---|
| committer | Nadeem Vawda <nadeem.vawda@gmail.com> | 2011-08-28 11:29:35 +0200 |
| commit | 44c6ef50af9980f33f6373440f0afc9cfa800c86 (patch) | |
| tree | c2d25fb835323b271b15b10a55cace32b690e6bf /Modules/zlibmodule.c | |
| parent | 76f570a9c63eca7dda7d88c0827d34ee1ea53270 (diff) | |
| parent | 524148ad7a3e5420abf867b1e30017b5ca2311a4 (diff) | |
| download | cpython-git-44c6ef50af9980f33f6373440f0afc9cfa800c86.tar.gz | |
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.
Diffstat (limited to 'Modules/zlibmodule.c')
| -rw-r--r-- | Modules/zlibmodule.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c index 711004e63f..f1f84e3b22 100644 --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -53,7 +53,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: |
