Skip to content

gh-157564: Don't clear sqlite3 statement on re-entrant execute during fetch - #157578

Open
nouraellm wants to merge 1 commit into
python:mainfrom
nouraellm:gh-157564-sqlite-reentrant-execute-fetch
Open

nouraellm wants to merge 1 commit into
python:mainfrom
nouraellm:gh-157564-sqlite-reentrant-execute-fetch

Conversation

@nouraellm

@nouraellm nouraellm commented Sep 15, 2026

Copy link
Copy Markdown

Nested Cursor.execute() during fetch is already rejected with ProgrammingError ("Recursive use of cursors not allowed"). The shared error path in _pysqlite_query_execute still set locked=0 and Py_CLEAR'd self->statement, so the outer fetch then dereferenced a NULL statement in _pysqlite_fetch_one_row.

Return immediately when check_cursor() fails at entry instead of jumping to that cleanup. Add regression tests for text_factory and converter callbacks that call execute() mid-fetch.

Fixes #157564

…during fetch

Nested Cursor.execute() during fetch is already rejected with
ProgrammingError ("Recursive use of cursors not allowed"). The shared
error path in _pysqlite_query_execute still set locked=0 and
Py_CLEAR'd self->statement, so the outer fetch then dereferenced a
NULL statement in _pysqlite_fetch_one_row.

Return immediately when check_cursor() fails at entry instead of
jumping to that cleanup. Add regression tests for text_factory and
converter callbacks that call execute() mid-fetch.

Fixes python#157564
@python-cla-bot

python-cla-bot Bot commented Sep 15, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sqlite3 Cursor NULL-deref via reentrant execute() inside a text_factory/converter during fetch

1 participant