Fix some UBSAN false positives#6115
Merged
jhawthorn merged 2 commits intoruby:masterfrom Jul 12, 2022
Merged
Conversation
jhawthorn
approved these changes
Jul 12, 2022
Member
jhawthorn
left a comment
There was a problem hiding this comment.
Looks good to me! Just needs dependencies fixed
|
|
||
| #include "regparse.h" | ||
| #include <stdarg.h> | ||
| #include "internal/sanitizers.h" |
Member
There was a problem hiding this comment.
Because of this addition we need to run ruby tool/update-deps --fix (this is the cause of CI failing). It's a little finicky, ping me if you'd prefer I run it to fix the deps 😅.
| * defined. Also it can be compiled into a single LEA instruction. */ | ||
| const unsigned long j = i; | ||
| const unsigned long k = 2 * j + RUBY_FIXNUM_FLAG; | ||
| const unsigned long k = (j << 1) + RUBY_FIXNUM_FLAG; |
Member
There was a problem hiding this comment.
(We discussed this a little at work)
It seems like, even though C considers unsigned overflow defined for both << and *, UBSAN checks for overflow on *, but not <<. We figured that this UBSAN behaviour is probably safe to rely on, and doing this avoids having to NO_SANITIZE in this code that is exported in the C extension API.
(The output of gcc and clang w/o UBSAN is identical)
👍
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.
I tried building ruby with UBSAN and saw some false-positive results for "unsigned integer overflow". These changes fix the false-positives, without changing the behavior of the code.