Repository navigation
gh-151126: Check strdup result in readline on_completion
#156299
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
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 |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Raise :exc:`MemoryError` on allocation failure in the :mod:`!readline` | ||
| completion callback. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1272,6 +1272,10 @@ on_completion(const char *text, int state) | |
| goto error; | ||
| result = strdup(PyBytes_AS_STRING(encoded)); | ||
| Py_DECREF(encoded); | ||
| if (result == NULL) { | ||
| PyErr_NoMemory(); | ||
|
Contributor
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. I don't think this works right as the
Contributor
Author
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. 🤔 You're right, indeed. Looking a bit more at it, I'm starting to wonder if the lack of checking So I'm not quite sure what I should do here. It seems like actually bubbling the exception all the way up to Alternatively, it might make sense to just explicitly ignore the result of |
||
| goto error; | ||
| } | ||
| } | ||
| Py_DECREF(r); | ||
| goto done; | ||
|
|
||
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 think this should actually change to _PyMem_Strdup while we're here
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.
Will do depending on whether we just close the PR or not!