-
Notifications
You must be signed in to change notification settings - Fork 228
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
handle null-byte case in scanformat (fixes #1105) #1106
Conversation
When there is no format to be found after a %, get_fmt_mapping returns NULL. It then gets called against strlen, which is a typical SEGV. Check for NULL aginst mapping, which signals a null format being specified.
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 would love to have a bit of information about what happened. And maybe that is just me.
I mean in the error message. |
Ah, I finally get it, @pepe, you mean that may be Do you have some specific ideas about what one might say in addition or instead? |
Position of the character in the string if possible? And thank you very much for trying to decipher my craps 😀 |
Ah I see. That might be nice. Though if you look above the newly added code, I think you'll see that there are a couple of other error messages which are very much in the same style (i.e. no positional info) :) |
there was a request to improve the error message, but the whole function has non-informative errors. (both functions, actually, since the code is duplicated) as such, instead of catching it directly, address the assumption that led to the SIGSEGV and let it be caught by the functions themselves, thus reusing existing error messages (which can then be improved separately).
It's rather complicated because the information on the string format location is partial and lost (see: the "% " example), as well as disparate between the two functions (one of them doesn't hold an intermediary pointer), which is why the existing error messages don't hold location information.
This means that if a pass was ever done on those two functions (including to potentially deduplicate them), this case would benefit alongside all the other cases with location information. |
Oh thank you both. |
Looks like a good fix to me right now, we could definitely improve some of the error handling in some cases, but I think it is more important to fix segfaults and things before worrying about the error case flow |
Indeed. I am sorry about the not needed discussion. |
When there is no format to be found after a %, get_fmt_mapping returns NULL.
It then gets called against strlen, which is a typical SEGV.
Check for NULL aginst mapping, which signals a null format being specified.
Note that there are other edge-conditions present.
Namely, consider:
(printf "hello % " "dave")
(format is still null).Meanwhile,
(printf "hello % s" "dave")
(outputs "hello dave").