]> granicus.if.org Git - python/commitdiff
#3312: fix two sqlite3 crashes.
authorGeorg Brandl <georg@python.org>
Wed, 16 Jul 2008 22:33:18 +0000 (22:33 +0000)
committerGeorg Brandl <georg@python.org>
Wed, 16 Jul 2008 22:33:18 +0000 (22:33 +0000)
Lib/sqlite3/test/regression.py
Misc/NEWS
Modules/_sqlite/connection.c
Modules/_sqlite/module.c

index 2cc8f30e53e09cd67b62977888107a59f9e13a04..d07c237fd4c39071ccdedb28e492977234279b9e 100644 (file)
@@ -153,6 +153,20 @@ class RegressionTests(unittest.TestCase):
         con.execute("insert into foo(bar) values (5)")
         con.execute(SELECT)
 
+    def CheckRegisterAdapter(self):
+        """
+        See issue 3312.
+        """
+        self.assertRaises(TypeError, sqlite.register_adapter, {}, None)
+
+    def CheckSetIsolationLevel(self):
+        """
+        See issue 3312.
+        """
+        con = sqlite.connect(":memory:")
+        self.assertRaises(UnicodeEncodeError, setattr, con,
+                          "isolation_level", u"\xe9")
+
 
 def suite():
     regression_suite = unittest.makeSuite(RegressionTests, "Check")
index 357ea501c2ac799772c90f4d7e14746389735f36..1ee2b429130accb4f01b4e2392532eb5f5945412 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -63,6 +63,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #3312: Fix two crashes in sqlite3.
+
 - Issue #1608818: Fix misbehavior in os.listdir() if readdir() fails.
 
 - Issue #3125: Remove copy_reg in multiprocessing and replace it with
index 2071c332127ebefa1a738ce2c29f1688fc32aee5..46774c12c2fad6e4534140ffcc004b5b5929b390 100644 (file)
@@ -940,6 +940,7 @@ static int pysqlite_connection_set_isolation_level(pysqlite_Connection* self, Py
 {
     PyObject* res;
     PyObject* begin_statement;
+    char* begin_statement_str;
 
     Py_XDECREF(self->isolation_level);
 
@@ -972,12 +973,18 @@ static int pysqlite_connection_set_isolation_level(pysqlite_Connection* self, Py
             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 ceec418b2eeb3606c36e01ae2e898ffe51523b22..7640e923c8696214e567cb165d2b8ec2628af195 100644 (file)
@@ -147,6 +147,7 @@ static PyObject* module_register_adapter(PyObject* self, PyObject* args)
 {
     PyTypeObject* type;
     PyObject* caster;
+    int rc;
 
     if (!PyArg_ParseTuple(args, "OO", &type, &caster)) {
         return NULL;
@@ -159,7 +160,9 @@ static PyObject* module_register_adapter(PyObject* self, PyObject* args)
         pysqlite_BaseTypeAdapted = 1;
     }
 
-    microprotocols_add(type, (PyObject*)&pysqlite_PrepareProtocolType, caster);
+    rc = microprotocols_add(type, (PyObject*)&pysqlite_PrepareProtocolType, caster);
+    if (rc == -1)
+        return NULL;
 
     Py_INCREF(Py_None);
     return Py_None;