-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
bpo-31764: Prevent a crash in sqlite3.Cursor.close() in case the Cursor object is uninitialized #3958
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
Conversation
I wonder whether we should add However, i don't know how to produce code that would create a partially initialized |
Modules/_sqlite/cursor.c
Outdated
@@ -890,6 +890,11 @@ PyObject* pysqlite_noop(pysqlite_Connection* self, PyObject* args) | |||
|
|||
PyObject* pysqlite_cursor_close(pysqlite_Cursor* self, PyObject* args) | |||
{ | |||
if (self->connection == NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style nit: I think !foo
is more common than foo == NULL
in sqlite3 codebase. It would be nice to keep styling consistent within the module.
@@ -0,0 +1,2 @@ | |||
Prevent a crash in `sqlite3.Cursor.close()` in case the `Cursor` object is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use double backticks (``). I tried to explain why single backticks shouldn't be used at #3925 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not familiar with Sphinx, but i trust you are :)
So maybe https://devguide.python.org/committing/#what-s-new-and-news-entries should also recommend double backticks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I wasn't aware of that example in the devguide. I will update it, thanks!
Lib/sqlite3/test/regression.py
Outdated
@@ -188,6 +188,7 @@ def __init__(self, con): | |||
cur = Cursor(con) | |||
with self.assertRaises(sqlite.ProgrammingError): | |||
cur.execute("select 4+5").fetchall() | |||
self.assertRaises(sqlite.ProgrammingError, cur.close) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ProgrammingError
is raised by a lot of things so I wonder if we should add a test for the exception message to make it more future-proof.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All right. Should i also change the assertRaises()
that was already in CheckCursorConstructorCallCheck()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say let's do it only for new additions to the test.
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 |
@berkerpeksag What do you think about #3958 (comment)? |
I agree with you. There is no need to add additional code for hypothetical use cases. We can change it later if we find a way to create a partially initialized Cursor object. |
The author took comments in account.
…or object is uninitialized (pythonGH-3958) (cherry picked from commit edb13ae)
GH-4303 is a backport of this pull request to the 3.6 branch. |
…or object is uninitialized (python#3958)
In addition, add a test to
test_sqlite
to make sure that the crash is no more.https://bugs.python.org/issue31764