-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
bpo-31746: Fixed Segfaults in the sqlite module when uninitialized. #3946
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
Changes from all commits
bbe3a0e
b57a6af
9955edf
c0920c8
77b2946
0fcd075
d8b4dd6
51e7a9f
84326a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -118,11 +118,15 @@ pysqlite_connection_init(pysqlite_Connection *self, PyObject *args, | |||||||||||||||||
if (!isolation_level) { | ||||||||||||||||||
isolation_level = PyUnicode_FromString(""); | ||||||||||||||||||
if (!isolation_level) { | ||||||||||||||||||
PyErr_SetString(pysqlite_ProgrammingError, "Isolation level could not be set."); | ||||||||||||||||||
return -1; | ||||||||||||||||||
} | ||||||||||||||||||
} else { | ||||||||||||||||||
Py_INCREF(isolation_level); | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
self->initialized = 1; | ||||||||||||||||||
|
||||||||||||||||||
lielfr marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
Py_CLEAR(self->isolation_level); | ||||||||||||||||||
if (pysqlite_connection_set_isolation_level(self, isolation_level, NULL) < 0) { | ||||||||||||||||||
Py_DECREF(isolation_level); | ||||||||||||||||||
|
@@ -250,8 +254,19 @@ pysqlite_connection_dealloc(pysqlite_Connection *self) | |||||||||||||||||
*/ | ||||||||||||||||||
int pysqlite_connection_register_cursor(pysqlite_Connection* connection, PyObject* cursor) | ||||||||||||||||||
{ | ||||||||||||||||||
if (!connection || !connection->cursors) { | ||||||||||||||||||
PyErr_Format(pysqlite_ProgrammingError, | ||||||||||||||||||
lielfr marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
"Base Connection.__init__ not called."); | ||||||||||||||||||
goto error; | ||||||||||||||||||
} | ||||||||||||||||||
PyObject* weakref; | ||||||||||||||||||
|
||||||||||||||||||
if (!connection->cursors) { | ||||||||||||||||||
PyErr_SetString(pysqlite_ProgrammingError, | ||||||||||||||||||
"Base Connection.__init__ not called."); | ||||||||||||||||||
goto error; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
weakref = PyWeakref_NewRef((PyObject*)cursor, NULL); | ||||||||||||||||||
if (!weakref) { | ||||||||||||||||||
goto error; | ||||||||||||||||||
|
@@ -281,6 +296,11 @@ static PyObject * | |||||||||||||||||
pysqlite_connection_cursor_impl(pysqlite_Connection *self, PyObject *factory) | ||||||||||||||||||
/*[clinic end generated code: output=562432a9e6af2aa1 input=4127345aa091b650]*/ | ||||||||||||||||||
{ | ||||||||||||||||||
if (self == NULL) { | ||||||||||||||||||
return NULL; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
static char *kwlist[] = {"factory", NULL}; | ||||||||||||||||||
Comment on lines
+299
to
+303
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not needed if |
||||||||||||||||||
PyObject* cursor; | ||||||||||||||||||
|
||||||||||||||||||
if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) { | ||||||||||||||||||
|
@@ -323,6 +343,12 @@ pysqlite_connection_close_impl(pysqlite_Connection *self) | |||||||||||||||||
/*[clinic end generated code: output=a546a0da212c9b97 input=3d58064bbffaa3d3]*/ | ||||||||||||||||||
{ | ||||||||||||||||||
int rc; | ||||||||||||||||||
|
||||||||||||||||||
if (!self->statements) { | ||||||||||||||||||
PyErr_SetString(pysqlite_ProgrammingError, | ||||||||||||||||||
"Base Connection.__init__ not called."); | ||||||||||||||||||
return NULL; | ||||||||||||||||||
} | ||||||||||||||||||
Comment on lines
+346
to
+351
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't it be better to handle this in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure about splitting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I'm not sure :) Let's leave it as it is; both Nit: |
||||||||||||||||||
|
||||||||||||||||||
if (!pysqlite_check_thread(self)) { | ||||||||||||||||||
return NULL; | ||||||||||||||||||
|
@@ -1225,6 +1251,11 @@ int pysqlite_check_thread(pysqlite_Connection* self) | |||||||||||||||||
|
||||||||||||||||||
static PyObject* pysqlite_connection_get_isolation_level(pysqlite_Connection* self, void* unused) | ||||||||||||||||||
{ | ||||||||||||||||||
if (!self || !self->isolation_level) { | ||||||||||||||||||
PyErr_Format(pysqlite_ProgrammingError, | ||||||||||||||||||
"Object is null or isolation_level is uninitialized."); | ||||||||||||||||||
return 0; | ||||||||||||||||||
} | ||||||||||||||||||
Comment on lines
+1254
to
+1258
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If
Suggested change
|
||||||||||||||||||
return Py_NewRef(self->isolation_level); | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
|
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.
Other getters raise a
ProgrammingError
when they are called on an uninitializedConnection
object.IMHO this should be the same here.