classification
Title: [sqlite3] sqlite3.connect() segfaults if given a faulty Connection factory
Type: crash Stage:
Components: Library (Lib) Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: berker.peksag, erlendaasland, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2021-03-04 10:54 by erlendaasland, last changed 2021-03-04 10:54 by erlendaasland.

Files
File name Uploaded Description Edit
patch.diff erlendaasland, 2021-03-04 10:54
Messages (1)
msg388082 - (view) Author: Erlend Egeberg Aasland (erlendaasland) * Date: 2021-03-04 10:54
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)
History
Date User Action Args
2021-03-04 10:54:37erlendaaslandcreate