-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
PYTHON-5013 Add NULL checks in InvalidDocument bson handling #2049
Changes from 1 commit
dc2cc10
005d942
7834214
fa60555
79a8c57
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 |
---|---|---|
|
@@ -1747,6 +1747,9 @@ int write_dict(PyObject* self, buffer_t buffer, | |
PyObject *etype = NULL, *evalue = NULL, *etrace = NULL; | ||
PyErr_Fetch(&etype, &evalue, &etrace); | ||
PyObject *InvalidDocument = _error("InvalidDocument"); | ||
if (InvalidDocument == NULL) { | ||
return 0; | ||
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 return case will leak 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. Fixed |
||
} | ||
|
||
if (top_level && InvalidDocument && PyErr_GivenExceptionMatches(etype, InvalidDocument)) { | ||
|
||
|
@@ -1760,6 +1763,9 @@ int write_dict(PyObject* self, buffer_t buffer, | |
if (msg) { | ||
// Prepend doc to the existing message | ||
PyObject *dict_str = PyObject_Str(dict); | ||
if (dict_str == NULL) { | ||
return 0; | ||
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. Same leak comment here except we'll also leak more variables, eg msg. 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. Fixed |
||
} | ||
PyObject *new_msg = PyUnicode_FromFormat("Invalid document %s | %s", PyUnicode_AsUTF8(dict_str), PyUnicode_AsUTF8(msg)); | ||
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. Could you fix the indentation on line 1776? 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. Also I believe PyUnicode_AsUTF8 can return NULL on error so we'll need checks there too. Unless there's a simpler API to construct this string that does the NULL checks for us. 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. Fixed |
||
Py_DECREF(dict_str); | ||
|
||
|
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 just realized there's a larger problem here. This logic is only in place for the
is_dict
fast path where it should be added generically for any mapping.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.
Okay, I'll see if I can factor this out.