[New-bugs-announce] [issue45126] [sqlite3] cleanup and harden connection init

Erlend E. Aasland report at bugs.python.org
Tue Sep 7 07:46:02 EDT 2021


New submission from Erlend E. Aasland <erlend.aasland at innova.no>:

Quoting Petr Viktorin in PR 27940, https://github.com/python/cpython/pull/27940#discussion_r703424148:

- db is not set to NULL if init fails.
- This segfaults for me:

  import sqlite3

  conn = sqlite3.connect(':memory:')
  conn.execute('CREATE TABLE foo (bar)')

  try:
      conn.__init__('/bad-file/')
  except sqlite3.OperationalError:
      pass

  conn.execute('INSERT INTO foo (bar) VALUES (1), (2), (3), (4)')


Other issues:
- reinitialisation is not handled gracefully
- __init__ is messy; members are initialised here and there


Suggested to reorder connection __init__ in logical groups to more easily handle errors:
  1. handle reinit
  2. open and configure database
  3. create statement LRU cache and weak ref cursor list
  4. initialise members in the order they're defined in connection.h
  5. set isolation level, since it's a weird case anyway

----------
components: Extension Modules
messages: 401248
nosy: erlendaasland, petr.viktorin
priority: normal
severity: normal
status: open
title: [sqlite3] cleanup and harden connection init
versions: Python 3.11

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45126>
_______________________________________


More information about the New-bugs-announce mailing list