[Python-checkins] r65040 - in python/trunk: Lib/sqlite3/test/regression.py Misc/NEWS Modules/_sqlite/connection.c Modules/_sqlite/module.c
georg.brandl
python-checkins at python.org
Thu Jul 17 00:33:18 CEST 2008
Author: georg.brandl
Date: Thu Jul 17 00:33:18 2008
New Revision: 65040
Log:
#3312: fix two sqlite3 crashes.
Modified:
python/trunk/Lib/sqlite3/test/regression.py
python/trunk/Misc/NEWS
python/trunk/Modules/_sqlite/connection.c
python/trunk/Modules/_sqlite/module.c
Modified: python/trunk/Lib/sqlite3/test/regression.py
==============================================================================
--- python/trunk/Lib/sqlite3/test/regression.py (original)
+++ python/trunk/Lib/sqlite3/test/regression.py Thu Jul 17 00:33:18 2008
@@ -153,6 +153,20 @@
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")
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Thu Jul 17 00:33:18 2008
@@ -63,6 +63,8 @@
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
Modified: python/trunk/Modules/_sqlite/connection.c
==============================================================================
--- python/trunk/Modules/_sqlite/connection.c (original)
+++ python/trunk/Modules/_sqlite/connection.c Thu Jul 17 00:33:18 2008
@@ -940,6 +940,7 @@
{
PyObject* res;
PyObject* begin_statement;
+ char* begin_statement_str;
Py_XDECREF(self->isolation_level);
@@ -972,12 +973,18 @@
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);
}
Modified: python/trunk/Modules/_sqlite/module.c
==============================================================================
--- python/trunk/Modules/_sqlite/module.c (original)
+++ python/trunk/Modules/_sqlite/module.c Thu Jul 17 00:33:18 2008
@@ -147,6 +147,7 @@
{
PyTypeObject* type;
PyObject* caster;
+ int rc;
if (!PyArg_ParseTuple(args, "OO", &type, &caster)) {
return NULL;
@@ -159,7 +160,9 @@
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;
More information about the Python-checkins
mailing list