]> granicus.if.org Git - python/commitdiff
Issue #4046: Backport of issue #3312's patch: fixes two crashes in the sqlite3
authorGerhard Häring <gh@ghaering.de>
Wed, 8 Oct 2008 08:45:16 +0000 (08:45 +0000)
committerGerhard Häring <gh@ghaering.de>
Wed, 8 Oct 2008 08:45:16 +0000 (08:45 +0000)
module.

Misc/NEWS
Modules/_sqlite/connection.c
Modules/_sqlite/module.c

index dde30ae6c87a139ab643370ee15d1ffb8d797c31..a492d461315142186200c1f4973f20509282779d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -215,6 +215,9 @@ Extension Modules
 - Issue #1471: Arguments to fcntl.ioctl are no longer broken on 64-bit OpenBSD
   and similar platforms due to sign extension.
 
+- Issue #3312: Fix two crashes in sqlite3.
+
+
 Tests
 -----
 
index 703af15fa939c2faee575b0028e2d8d7ed44c672..d4916882524298f182095fc6040495cac471b04f 100644 (file)
@@ -822,6 +822,7 @@ static int connection_set_isolation_level(Connection* self, PyObject* isolation_
 {
     PyObject* res;
     PyObject* begin_statement;
+    char* begin_statement_str;
 
     Py_XDECREF(self->isolation_level);
 
@@ -854,12 +855,18 @@ static int connection_set_isolation_level(Connection* self, PyObject* isolation_
             return -1;
         }
 
-        self->begin_statement = PyMem_Malloc(PyString_Size(begin_statement) + 2);
+        begin_statement_str = PyString_AsString(begin_statement);
+        if (!begin_statement_str) {
+            Py_DECREF(begin_statement);
+            return -1;
+        }
+        self->begin_statement = PyMem_Malloc(strlen(begin_statement_str) + 2);
         if (!self->begin_statement) {
+            Py_DECREF(begin_statement);
             return -1;
         }
 
-        strcpy(self->begin_statement, PyString_AsString(begin_statement));
+        strcpy(self->begin_statement, begin_statement_str);
         Py_DECREF(begin_statement);
     }
 
index 606454ca1f8b769469fc6b6dbeeb8872443607db..bfaf730e0ccfe5c24a5d234fa0b09a7380de033f 100644 (file)
@@ -128,12 +128,15 @@ static PyObject* module_register_adapter(PyObject* self, PyObject* args, PyObjec
 {
     PyTypeObject* type;
     PyObject* caster;
+    int rc;
 
     if (!PyArg_ParseTuple(args, "OO", &type, &caster)) {
         return NULL;
     }
 
-    microprotocols_add(type, (PyObject*)&SQLitePrepareProtocolType, caster);
+    rc = microprotocols_add(type, (PyObject*)&SQLitePrepareProtocolType, caster);
+    if (rc == -1)
+        return NULL;
 
     Py_INCREF(Py_None);
     return Py_None;