-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[random] Suppress UBSan #9060
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
[random] Suppress UBSan #9060
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 |
---|---|---|
|
@@ -61,6 +61,14 @@ | |
|
||
#if __has_feature(memory_sanitizer) | ||
# include <sanitizer/msan_interface.h> | ||
# define MSAN_UNPOISON(ptr, size) __msan_unpoison((ptr), (size)); | ||
#else | ||
# define MSAN_UNPOISON(ptr, size) | ||
#endif | ||
#if __has_feature(undefined_behavior_sanitizer) || ZEND_GCC_VERSION >= 8000 | ||
# define UBSAN_SUPPRESS_SIGNED_INTEGER_OVERFLOW __attribute__((no_sanitize("signed-integer-overflow"))) | ||
#else | ||
# define UBSAN_SUPPRESS_SIGNED_INTEGER_OVERFLOW | ||
#endif | ||
|
||
#include "random_arginfo.h" | ||
|
@@ -317,7 +325,7 @@ PHPAPI zend_object *php_random_engine_common_clone_object(zend_object *object) | |
} | ||
|
||
/* {{{ php_random_range */ | ||
PHPAPI zend_long php_random_range(const php_random_algo *algo, php_random_status *status, zend_long min, zend_long max) | ||
UBSAN_SUPPRESS_SIGNED_INTEGER_OVERFLOW PHPAPI zend_long php_random_range(const php_random_algo *algo, php_random_status *status, zend_long min, zend_long max) | ||
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. Can we not avoid this undefined behavior by using unsigned integers and only then casting them to signed? I think all we might need is: return (zend_long) (rand_range64(algo, status, umax) + min); 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. Related, 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. @iluuu1994 @guilliamxavier
|
||
{ | ||
zend_ulong umax = max - min; | ||
|
||
|
@@ -539,10 +547,8 @@ PHPAPI int php_random_bytes(void *bytes, size_t size, bool should_throw) | |
} | ||
} | ||
|
||
# if __has_feature(memory_sanitizer) | ||
/* MSan does not instrument manual syscall invocations. */ | ||
__msan_unpoison(bytes + read_bytes, n); | ||
# endif | ||
MSAN_UNPOISON(bytes + read_bytes, n); | ||
read_bytes += (size_t) n; | ||
} | ||
# endif | ||
|
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.
trailing semicolon to remove? (but why touch this part anyway?)
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.
This is because we initially used a similar macro branch. Revert back to the original.