Skip to content

Conversation

@picnixz
Copy link
Member

@picnixz picnixz commented Dec 27, 2025

FTR, the reason why execute is actually not affected is that the iterator we are taking is built from a list we create ourselves so it's not possible to have "bad" side effects.

@picnixz picnixz added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Dec 27, 2025
@picnixz picnixz changed the title gh-143198: fix SIGSEGV in sqlite3.execute[many] with re-entrant parameter iterator gh-143198: fix SIGSEGV in sqlite3.execute[many] with concurrent mutations Dec 27, 2025
@picnixz picnixz marked this pull request as draft December 27, 2025 15:19
@picnixz picnixz changed the title gh-143198: fix SIGSEGV in sqlite3.execute[many] with concurrent mutations gh-143198: fix SIGSEGV in sqlite3.executemany with concurrent mutations Dec 27, 2025
@picnixz picnixz marked this pull request as ready for review December 27, 2025 16:42
@picnixz
Copy link
Member Author

picnixz commented Dec 29, 2025

There were more UAFs that I could find...

@picnixz picnixz changed the title gh-143198: fix SIGSEGV in sqlite3.executemany with concurrent mutations gh-143198: fix some crashes in sqlite3.executemany with concurrent mutations Dec 29, 2025
@picnixz
Copy link
Member Author

picnixz commented Dec 29, 2025

@serhiy-storchaka So the split went well but... it's now a larger code =/ I also changed some variable names since we're talking about parameters everywhere but it's more arguments in this case or values. I can revert the change if you want (I'll make a commit for reverting and then we can decide whether to keep the revert or not) but I wanted to show you how it would be if the implementations are separate.

@picnixz
Copy link
Member Author

picnixz commented Dec 29, 2025

I feel that there are a lot of tests that are really looking-alike. It's kinda annoying to have redundancy... and it won't get any better with the other PRs for sqlite where we I need to test the callbacks.

@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented Dec 30, 2025

I also changed some variable names since we're talking about parameters everywhere but it's more arguments in this case or values.

I understand you, the term "parameter" is used here in different meaning from what we used to. But this makes the diff unnecessary large and makes harder to follow semantic changes. Can we leave this to a separate PR?

@picnixz
Copy link
Member Author

picnixz commented Dec 30, 2025

Ok, I'll revert the naming changes and all other styling stuff. And then I'll address it separately.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are still many pure cosmetic changes, but splitting execute/executemany was reverted (I do not know it the split would help readability). Could you please return to more early version?

If possible, I would prefer to add checks closer to the code that can be affected by closing the connection then to the code that can close the connection.

@picnixz picnixz force-pushed the fix/sqlite/uaf-in-cursor-143198 branch 5 times, most recently from 15f7823 to 6056bb2 Compare December 31, 2025 13:58
@picnixz picnixz force-pushed the fix/sqlite/uaf-in-cursor-143198 branch from 6056bb2 to 75b2a0c Compare December 31, 2025 14:00
@picnixz picnixz marked this pull request as draft December 31, 2025 14:04
@picnixz picnixz marked this pull request as ready for review December 31, 2025 14:04
@picnixz
Copy link
Member Author

picnixz commented Dec 31, 2025

Ok, let's avoid force-pushing more. I force pushed because I wanted a single commit for the follow-up PR

@picnixz
Copy link
Member Author

picnixz commented Dec 31, 2025

If possible, I would prefer to add checks closer to the code that can be affected by closing the connection then to the code that can close the connection.

This is not always possible and it's more prone to errors in the future. The connection may be closed but we would check it way later. I tried to only add checks when the code in question never uses the sqlite3 API (e.g., pysqlite_microprotocols_adapt is purely using the Python C API so it doesn't matter that the connection is alive or not).

I can't make the diff smaller though. It's the minimal diff on the C code I can do.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants