classification
Title: Py_DECREF->Py_XDECREF in Module/_sqlite/module.c
Type: Stage: resolved
Components: Extension Modules Versions: Python 3.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: belopolsky, brett.cannon, georg.brandl
Priority: release blocker Keywords: patch

Created on 2011-02-04 01:26 by brett.cannon, last changed 2011-02-04 20:30 by brett.cannon. This issue is now closed.

Files
File name Uploaded Description Edit
fix_sqlite.diff brett.cannon, 2011-02-04 01:26 Change a Py_DECREF to Py_XDECREF
Messages (4)
msg127853 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2011-02-04 01:26
Pretty straight forward change, but could potentially cause a NULL pointer deref in a rare situation.

diff --git a/Modules/_sqlite/module.c b/Modules/_sqlite/module.c
--- a/Modules/_sqlite/module.c
+++ b/Modules/_sqlite/module.c
@@ -329,7 +329,7 @@
         (pysqlite_statement_setup_types() < 0) ||
         (pysqlite_prepare_protocol_setup_types() < 0)
        ) {
-        Py_DECREF(module);
+        Py_XDECREF(module);
         return NULL;
     }
msg127859 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2011-02-04 02:21
It may be clearer and match Python coding style better to fix it as follows:


Index: Modules/_sqlite/module.c
===================================================================
--- Modules/_sqlite/module.c	(revision 88320)
+++ Modules/_sqlite/module.c	(working copy)
@@ -321,14 +321,16 @@
 
     module = PyModule_Create(&_sqlite3module);
 
-    if (!module ||
-        (pysqlite_row_setup_types() < 0) ||
-        (pysqlite_cursor_setup_types() < 0) ||
-        (pysqlite_connection_setup_types() < 0) ||
-        (pysqlite_cache_setup_types() < 0) ||
-        (pysqlite_statement_setup_types() < 0) ||
-        (pysqlite_prepare_protocol_setup_types() < 0)
-       ) {
+    if (module == NULL)
+        return NULL;
+
+    if (pysqlite_row_setup_types() < 0 ||
+        pysqlite_cursor_setup_types() < 0 ||
+        pysqlite_connection_setup_types() < 0 ||
+        pysqlite_cache_setup_types() < 0 ||
+        pysqlite_statement_setup_types() < 0 ||
+        pysqlite_prepare_protocol_setup_types() < 0)
+    {
         Py_DECREF(module);
         return NULL;
     }
msg127903 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2011-02-04 16:32
Either one of these fixes (I prefer Brett's since it's shorter) should make it into 3.2.
msg127938 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2011-02-04 20:30
py3k: r88337
3.1: 88339
2.7 (blocked): 88338
History
Date User Action Args
2011-02-04 20:30:43brett.cannonsetstatus: open -> closed
nosy: brett.cannon, georg.brandl, belopolsky
messages: + msg127938

resolution: fixed
stage: commit review -> resolved
2011-02-04 16:32:10georg.brandlsetnosy: brett.cannon, georg.brandl, belopolsky
messages: + msg127903
2011-02-04 02:21:36belopolskysetnosy: + belopolsky
messages: + msg127859
2011-02-04 01:26:08brett.cannoncreate