Skip to content
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

Address undefined behaviour by checking for null before incrementing pointer at end of do/while loop. #10472

Closed
wants to merge 1 commit into from

Conversation

jkeastbb
Copy link
Contributor

@jkeastbb jkeastbb commented Feb 10, 2023

This address undefined behaviour found using clang's UBsan:

curl/lib/setopt.c:177:14: runtime error: applying non-zero offset 1 to null pointer
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior curl/lib/setopt.c:177:14 in

@dfandrich
Copy link
Contributor

Does this actually fix a problem? The loop will already exit at the right time without this patch. Is this just a C spec compliance issue?

@jkeastbb
Copy link
Contributor Author

I haven't observed this actually breaking but the issue was flagged by clang's Undefined Behaviour sanitizer:

`
curl/lib/setopt.c:177:14: runtime error: applying non-zero offset 1 to null pointer
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior curl/lib/setopt.c:177:14 in

`
This change resolves the issue flagged.

@dfandrich
Copy link
Contributor

That looks fine to me then. Would you update the description to mention ubsan?

@jkeastbb
Copy link
Contributor Author

That looks fine to me then. Would you update the description to mention ubsan?

Okay, thanks, I've done that now. Sorry, I wasn't sure what details were expected. Hope it is okay now.

@dfandrich dfandrich closed this in 635bf5a Feb 11, 2023
@dfandrich
Copy link
Contributor

It's the git commit that's the one more people will see when studying the code, rather than the PR description. I've updated that in the same way and committed it. Thanks for the contribution!

bch pushed a commit to bch/curl that referenced this pull request Jul 19, 2023
This addresses undefined behaviour found using clang's UBsan:

curl/lib/setopt.c:177:14: runtime error: applying non-zero offset 1 to null pointer
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior curl/lib/setopt.c:177:14 in

Closes curl#10472
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants