Skip to content

bpo-41815: SQLite: segfault if backup called on closed database #22322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 20, 2020
Merged

bpo-41815: SQLite: segfault if backup called on closed database #22322

merged 1 commit into from
Sep 20, 2020

Conversation

pdmccormick
Copy link
Contributor

@pdmccormick pdmccormick commented Sep 19, 2020

bpo-41815: SQLite: fix segfault if backup called on closed database

Attempting to backup a closed database will trigger segfault:

import sqlite3
target = sqlite3.connect(':memory:')
source = sqlite3.connect(':memory:')
source.close()
source.backup(target)

https://bugs.python.org/issue41815

Automerge-Triggered-By: @aeros

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

Recognized GitHub username

We couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames:

@pdmccormick

This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

Copy link
Contributor

@aeros aeros left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @pdmccormick, and welcome! The patch and test looks good to me, but it definitely could use a Misc/NEWS entry (see below for details).

I can confirm the segfault on master with the following (the original replication had a slight typo: "sqlite" -> "sqlite3" or it should be "import sqlite3 as sqlite" as is done in the source)

Python 3.10.0a0 (heads/master:c8c70e7876, Sep 19 2020, 21:28:47) 
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> target = sqlite3.connect(':memory:')
>>> source = sqlite3.connect(':memory:')
>>> source.close()
>>> source.backup(target)
[1]    17258 segmentation fault (core dumped)  ./python

The proposed changes in the PR addresses the segfault, and appropriately raises sqlite3.ProgrammingError

Python 3.10.0a0 (heads/bpo-41815-sqlite-closed-backup:9aee01c7be, Sep 19 2020, 22:06:20) 
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> target = sqlite3.connect(':memory:')
>>> source = sqlite3.connect(":memory:")
>>> source.close()
>>> source.backup(target)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
sqlite3.ProgrammingError: Cannot operate on a closed database.
>>> 

I've also confirmed the segfault on the following versions: 3.9, 3.8. With 3.7 and below being security-only (or EoL far back enough), this fix should be backported only to 3.9 and 3.8.

However, I believe we do need approval from the release manager with both 3.9.0 and 3.8.6 currently being in the release candidate phase, and with this being a crash, this should be included IMO. I'll add Lukasz to the nosy list in the bpo issue, and elevate priority to release blocker.

Also, the placement of the additional check looks good to me, and the test sufficiently replicates the crash. The only thing that this is missing is a Misc/NEWS entry, which can be easily added with blurb it. Something succinct such as "Fix SQLite3 segfault when backing up closed database." should work (and optional attribution, such as "Contributed by <Name>."). A Misc/NEWS entry is generally necessary for any non-trivial changes, and I'd definitely consider this to be non-trivial (even if the surface area is small) since it fixes a segfault that's simple to replicate.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

And if you don't make the requested changes, you will be put in the comfy chair!

@pdmccormick
Copy link
Contributor Author

Thank you for the review and guidance @aeros! I have made the requested changes; please review again.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@aeros: please review the changes made to this pull request.

@bedevere-bot bedevere-bot requested a review from aeros September 20, 2020 03:19
Copy link
Contributor

@aeros aeros left a comment

Choose a reason for hiding this comment

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

LGTM. I'll proceed with merging to master, but waiting on @ambv for the backports to 3.9 and 3.8. If some time passes and those branches are no longer in release candidate phase (see version PEPs for dates), feel free to ping me as a reminder to add the labels to trigger the automated backports.

@miss-islington
Copy link
Contributor

Thanks @pdmccormick for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@miss-islington
Copy link
Contributor

Thanks @pdmccormick for the PR 🌮🎉.. I'm working now to backport this PR to: 3.9.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 21, 2020
…onGH-22322)

GH- [bpo-41815](): SQLite: fix segfault if backup called on closed database

Attempting to backup a closed database will trigger segfault:

```python
import sqlite3
target = sqlite3.connect(':memory:')
source = sqlite3.connect(':memory:')
source.close()
source.backup(target)
```
(cherry picked from commit bfee9fa)

Co-authored-by: Peter McCormick <[email protected]>
@bedevere-bot bedevere-bot removed the needs backport to 3.9 only security fixes label Sep 21, 2020
@bedevere-bot
Copy link

GH-22344 is a backport of this pull request to the 3.9 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 21, 2020
…onGH-22322)

GH- [bpo-41815](): SQLite: fix segfault if backup called on closed database

Attempting to backup a closed database will trigger segfault:

```python
import sqlite3
target = sqlite3.connect(':memory:')
source = sqlite3.connect(':memory:')
source.close()
source.backup(target)
```
(cherry picked from commit bfee9fa)

Co-authored-by: Peter McCormick <[email protected]>
@bedevere-bot
Copy link

GH-22345 is a backport of this pull request to the 3.8 branch.

miss-islington added a commit that referenced this pull request Sep 21, 2020
…2322)

GH- [bpo-41815](): SQLite: fix segfault if backup called on closed database

Attempting to backup a closed database will trigger segfault:

```python
import sqlite3
target = sqlite3.connect(':memory:')
source = sqlite3.connect(':memory:')
source.close()
source.backup(target)
```
(cherry picked from commit bfee9fa)

Co-authored-by: Peter McCormick <[email protected]>
miss-islington added a commit that referenced this pull request Sep 21, 2020
…2322)

GH- [bpo-41815](): SQLite: fix segfault if backup called on closed database

Attempting to backup a closed database will trigger segfault:

```python
import sqlite3
target = sqlite3.connect(':memory:')
source = sqlite3.connect(':memory:')
source.close()
source.backup(target)
```
(cherry picked from commit bfee9fa)

Co-authored-by: Peter McCormick <[email protected]>
@ambv
Copy link
Contributor

ambv commented Oct 4, 2020

3.9 backport goes into 3.9.0.

ambv pushed a commit to ambv/cpython that referenced this pull request Oct 4, 2020
…onGH-22322)

GH- [bpo-41815](): SQLite: fix segfault if backup called on closed database

Attempting to backup a closed database will trigger segfault:

```python
import sqlite3
target = sqlite3.connect(':memory:')
source = sqlite3.connect(':memory:')
source.close()
source.backup(target)
```
(cherry picked from commit bfee9fa)

Co-authored-by: Peter McCormick <[email protected]>
xzy3 pushed a commit to xzy3/cpython that referenced this pull request Oct 18, 2020
…onGH-22322)

# [bpo-41815](): SQLite: fix segfault if backup called on closed database

Attempting to backup a closed database will trigger segfault:

```python
import sqlite3
target = sqlite3.connect(':memory:')
source = sqlite3.connect(':memory:')
source.close()
source.backup(target)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants