[issue43398] [sqlite3] sqlite3.connect() segfaults if given a faulty Connection factory
Erlend Egeberg Aasland
report at bugs.python.org
Thu Mar 4 05:54:37 EST 2021
New submission from Erlend Egeberg Aasland <erlend.aasland at innova.no>:
If the connection factory __init__ method fails, we hit a seg. fault when pysqlite_do_all_statements() is called to clean up the defect connection: PyList_Size received a NULL pointer.
Suggested fix:
Split pysqlite_do_all_statements() in two: one function for resetting cursors, and one for resetting/finalising statements. In each function, check if the respective lists are NULL pointers before iterating. See attached proposed patch.
Test:
def test_invalid_connection_factory(self):
class DefectFactory(sqlite.Connection):
def __init__(self, *args, **kwargs):
return None
self.con = sqlite.connect(":memory:", factory=DefectFactory)
----------
components: Library (Lib)
files: patch.diff
keywords: patch
messages: 388082
nosy: berker.peksag, erlendaasland, serhiy.storchaka
priority: normal
severity: normal
status: open
title: [sqlite3] sqlite3.connect() segfaults if given a faulty Connection factory
type: crash
versions: Python 3.10
Added file: https://bugs.python.org/file49850/patch.diff
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43398>
_______________________________________
More information about the Python-bugs-list
mailing list