diff options
author | Kevin Backhouse <kevinbackhouse@github.com> | 2022-07-12 19:48:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-12 11:48:10 -0700 |
commit | 8c1808151f4c1b44e8b0fe935c571f05b2641b8b (patch) | |
tree | ed7dc9e5aac6945cae8df53e3f3ec1df6e120319 | |
parent | 8309b1366c3307ab8d9cda5b61b91540cf6cc8aa (diff) |
Fix some UBSAN false positives (#6115)
* Fix some UBSAN false positives.
* ruby tool/update-deps --fix
Notes
Notes:
Merged-By: jhawthorn <john@hawthorn.email>
-rw-r--r-- | common.mk | 4 | ||||
-rw-r--r-- | include/ruby/internal/arithmetic/long.h | 2 | ||||
-rw-r--r-- | parse.y | 6 | ||||
-rw-r--r-- | regparse.c | 3 |
4 files changed, 11 insertions, 4 deletions
@@ -12898,10 +12898,14 @@ regexec.$(OBJEXT): {$(VPATH)}st.h regexec.$(OBJEXT): {$(VPATH)}subst.h regparse.$(OBJEXT): $(hdrdir)/ruby.h regparse.$(OBJEXT): $(hdrdir)/ruby/ruby.h +regparse.$(OBJEXT): $(top_srcdir)/internal/compilers.h +regparse.$(OBJEXT): $(top_srcdir)/internal/sanitizers.h +regparse.$(OBJEXT): $(top_srcdir)/internal/warnings.h regparse.$(OBJEXT): {$(VPATH)}assert.h regparse.$(OBJEXT): {$(VPATH)}backward/2/assume.h regparse.$(OBJEXT): {$(VPATH)}backward/2/attributes.h regparse.$(OBJEXT): {$(VPATH)}backward/2/bool.h +regparse.$(OBJEXT): {$(VPATH)}backward/2/gcc_version_since.h regparse.$(OBJEXT): {$(VPATH)}backward/2/inttypes.h regparse.$(OBJEXT): {$(VPATH)}backward/2/limits.h regparse.$(OBJEXT): {$(VPATH)}backward/2/long_long.h diff --git a/include/ruby/internal/arithmetic/long.h b/include/ruby/internal/arithmetic/long.h index 792f7be179..6b8fd8ffc3 100644 --- a/include/ruby/internal/arithmetic/long.h +++ b/include/ruby/internal/arithmetic/long.h @@ -115,7 +115,7 @@ RB_INT2FIX(long i) /* :NOTE: VALUE can be wider than long. As j being unsigned, 2j+1 is fully * 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; const long l = k; const SIGNED_VALUE m = l; /* Sign extend */ const VALUE n = m; @@ -232,12 +232,12 @@ enum { }; #define NUMPARAM_ID_P(id) numparam_id_p(id) -#define NUMPARAM_ID_TO_IDX(id) (unsigned int)(((id) >> ID_SCOPE_SHIFT) - tNUMPARAM_1 + 1) -#define NUMPARAM_IDX_TO_ID(idx) TOKEN2LOCALID((tNUMPARAM_1 + (idx) - 1)) +#define NUMPARAM_ID_TO_IDX(id) (unsigned int)(((id) >> ID_SCOPE_SHIFT) - (tNUMPARAM_1 - 1)) +#define NUMPARAM_IDX_TO_ID(idx) TOKEN2LOCALID((tNUMPARAM_1 - 1 + (idx))) static int numparam_id_p(ID id) { - if (!is_local_id(id)) return 0; + if (!is_local_id(id) || id < (tNUMPARAM_1 << ID_SCOPE_SHIFT)) return 0; unsigned int idx = NUMPARAM_ID_TO_IDX(id); return idx > 0 && idx <= NUMPARAM_MAX; } diff --git a/regparse.c b/regparse.c index 309749033d..4ebd5f1c46 100644 --- a/regparse.c +++ b/regparse.c @@ -37,6 +37,7 @@ #include "regparse.h" #include <stdarg.h> +#include "internal/sanitizers.h" #define WARN_BUFSIZE 256 @@ -394,6 +395,8 @@ str_end_cmp(st_data_t xp, st_data_t yp) return 0; } +NO_SANITIZE("unsigned-integer-overflow", static st_index_t str_end_hash(st_data_t xp)); + static st_index_t str_end_hash(st_data_t xp) { |