ruby-changes:72520
From: Kevin <ko1@a...>
Date: Wed, 13 Jul 2022 03:48:25 +0900 (JST)
Subject: [ruby-changes:72520] 8c1808151f (master): Fix some UBSAN false positives (#6115)
https://git.ruby-lang.org/ruby.git/commit/?id=8c1808151f From 8c1808151f4c1b44e8b0fe935c571f05b2641b8b Mon Sep 17 00:00:00 2001 From: Kevin Backhouse <kevinbackhouse@g...> Date: Tue, 12 Jul 2022 19:48:10 +0100 Subject: Fix some UBSAN false positives (#6115) * Fix some UBSAN false positives. * ruby tool/update-deps --fix --- common.mk | 4 ++++ include/ruby/internal/arithmetic/long.h | 2 +- parse.y | 6 +++--- regparse.c | 3 +++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/common.mk b/common.mk index f401785cfb..fa6a6e9faf 100644 --- a/common.mk +++ b/common.mk @@ -12898,10 +12898,14 @@ regexec.$(OBJEXT): {$(VPATH)}st.h https://github.com/ruby/ruby/blob/trunk/common.mk#L12898 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) https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/arithmetic/long.h#L115 /* :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; diff --git a/parse.y b/parse.y index 081fc1c868..b4c3106b8c 100644 --- a/parse.y +++ b/parse.y @@ -232,12 +232,12 @@ enum { https://github.com/ruby/ruby/blob/trunk/parse.y#L232 }; #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 @@ https://github.com/ruby/ruby/blob/trunk/regparse.c#L37 #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) https://github.com/ruby/ruby/blob/trunk/regparse.c#L395 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) { -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/