Fix potential crash when calling an overloaded function - #1327
Merged
wjakob merged 6 commits intoSep 25, 2018
Conversation
The crash would occur if: - dispatcher() uses two-pass logic (because the target is overloaded and some arguments support conversions) - the first pass (with conversions disabled) doesn't find any matching overload - the second pass does find a matching overload, but its return value can't be converted to Python The code for formatting the error message assumed `it` still pointed to the selected overload, but during the second-pass loop `it` was nullptr. Fix by setting `it` correctly if a second-pass call returns a nullptr `handle`. Add a new test that segfaults without this fix.
jagerman
reviewed
Mar 21, 2018
| if (!result) { | ||
| // The error reporting logic below expects 'it' to be valid, as it would be | ||
| // if we'd encountered this failure in the first-pass loop. | ||
| for (it = overloads; it != &call.func; it = it->next) |
Member
There was a problem hiding this comment.
ISTM this could be simplified down to just:
if (!result)
it = &call.func;(unless I'm forgetting something about this code).
Collaborator
Author
There was a problem hiding this comment.
D'oh, right you are - I was getting confused about function_call vs function_record.
jagerman
reviewed
Mar 21, 2018
| struct NotRegistered {}; | ||
| struct StringWrapper { std::string str; }; | ||
| NotRegistered test_error_after_conversions(StringWrapper) { return {}; } | ||
|
|
Member
There was a problem hiding this comment.
These classes should be moved with the module definitions, and the function rewritten as a lambda, unless there's a good reason to keep them outside. (We try to enforce that style in the test suite, where possible, to keep the test cases as localized as possible within each test suite file, to makes it easier to read).
…in on second-pass error
…eturn-after-conversions
Collaborator
Author
…eturn-after-conversions
Collaborator
Author
Member
|
Apologies for the delay -- this looks good now. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The crash would occur if:
The code for formatting the error message assumed
itstill pointed to the selected overload,but during the second-pass loop
itwas nullptr. Fix by settingitcorrectly if a second-passcall returns a nullptr
handle. Add a new test that segfaults without this fix.