summaryrefslogtreecommitdiffstats
path: root/Modules/_sqlite
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-07-16 22:33:18 (GMT)
committerGeorg Brandl <georg@python.org>2008-07-16 22:33:18 (GMT)
commita24869ada70ab30f4e08d71cdefda644cc40c6b0 (patch)
tree74fee137cbc427d59b168e931ec8e66ec4671cc0 /Modules/_sqlite
parent4ed9be733b58712e3e91dafa5ab13cc0a6d99702 (diff)
downloadcpython-a24869ada70ab30f4e08d71cdefda644cc40c6b0.zip
cpython-a24869ada70ab30f4e08d71cdefda644cc40c6b0.tar.gz
cpython-a24869ada70ab30f4e08d71cdefda644cc40c6b0.tar.bz2
#3312: fix two sqlite3 crashes.
Diffstat (limited to 'Modules/_sqlite')
-rw-r--r--Modules/_sqlite/connection.c11
-rw-r--r--Modules/_sqlite/module.c5
2 files changed, 13 insertions, 3 deletions
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
index 2071c33..46774c1 100644
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -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);
}
diff --git a/Modules/_sqlite/module.c b/Modules/_sqlite/module.c
index ceec418..7640e92 100644
--- a/Modules/_sqlite/module.c
+++ b/Modules/_sqlite/module.c
@@ -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;