Kaydet (Commit) 6e055d78 authored tarafından Victor Stinner's avatar Victor Stinner

sqlite3: Fix a segfault on calling a connection with something else than a

string. Initialize all attributes to be able to call the statement destructor
on error.

Avoid also a duplicate connection in some tests: setUp() does already open a
connection (":memory:").
üst 93dd9b80
...@@ -232,8 +232,7 @@ class RegressionTests(unittest.TestCase): ...@@ -232,8 +232,7 @@ class RegressionTests(unittest.TestCase):
Verifies that running a PRAGMA statement that does an autocommit does Verifies that running a PRAGMA statement that does an autocommit does
work. This did not work in 2.5.3/2.5.4. work. This did not work in 2.5.3/2.5.4.
""" """
con = sqlite.connect(":memory:") cur = self.con.cursor()
cur = con.cursor()
cur.execute("create table foo(bar)") cur.execute("create table foo(bar)")
cur.execute("insert into foo(bar) values (5)") cur.execute("insert into foo(bar) values (5)")
...@@ -253,11 +252,17 @@ class RegressionTests(unittest.TestCase): ...@@ -253,11 +252,17 @@ class RegressionTests(unittest.TestCase):
def __hash__(self): def __hash__(self):
raise TypeError() raise TypeError()
var = NotHashable() var = NotHashable()
con = sqlite.connect(":memory:") self.assertRaises(TypeError, self.con.create_function, var)
self.assertRaises(TypeError, con.create_function, var) self.assertRaises(TypeError, self.con.create_aggregate, var)
self.assertRaises(TypeError, con.create_aggregate, var) self.assertRaises(TypeError, self.con.set_authorizer, var)
self.assertRaises(TypeError, con.set_authorizer, var) self.assertRaises(TypeError, self.con.set_progress_handler, var)
self.assertRaises(TypeError, con.set_progress_handler, var)
def CheckConnectionCall(self):
"""
Call a connection with a non-string SQL request: check error handling
of the statement constructor.
"""
self.assertRaises(sqlite.Warning, self.con, 1)
def suite(): def suite():
regression_suite = unittest.makeSuite(RegressionTests, "Check") regression_suite = unittest.makeSuite(RegressionTests, "Check")
......
...@@ -1197,6 +1197,12 @@ PyObject* pysqlite_connection_call(pysqlite_Connection* self, PyObject* args, Py ...@@ -1197,6 +1197,12 @@ PyObject* pysqlite_connection_call(pysqlite_Connection* self, PyObject* args, Py
return NULL; return NULL;
} }
statement->db = NULL;
statement->st = NULL;
statement->sql = NULL;
statement->in_use = 0;
statement->in_weakreflist = NULL;
rc = pysqlite_statement_create(statement, self, sql); rc = pysqlite_statement_create(statement, self, sql);
if (rc != SQLITE_OK) { if (rc != SQLITE_OK) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment