8000 Fix some UBSAN false positives (#6115) · ruby/ruby@8c18081 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8c18081

Browse files
Fix some UBSAN false positives (#6115)
* Fix some UBSAN false positives. * ruby tool/update-deps --fix
1 parent 8309b13 commit 8c18081

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

common.mk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12898,10 +12898,14 @@ regexec.$(OBJEXT): {$(VPATH)}st.h
1289812898
regexec.$(OBJEXT): {$(VPATH)}subst.h
1289912899
regparse.$(OBJEXT): $(hdrdir)/ruby.h
1290012900
regparse.$(OBJEXT): $(hdrdir)/ruby/ruby.h
12901+
regparse.$(OBJEXT): $(top_srcdir)/internal/compilers.h
12902+
regparse.$(OBJEXT): $(top_srcdir)/internal/sanitizers.h
12903+
regparse.$(OBJEXT): $(top_srcdir)/internal/warnings.h
1290112904
regparse.$(OBJEXT): {$(VPATH)}assert.h
1290212905
regparse.$(OBJEXT): {$(VPATH)}backward/2/assume.h
1290312906
regparse.$(OBJEXT): {$(VPATH)}backward/2/attributes.h
1290412907
regparse.$(OBJEXT): {$(VPATH)}backward/2/bool.h
12908+
regparse.$(OBJEXT): {$(VPATH)}backward/2/gcc_version_since.h
1290512909
regparse.$(OBJEXT): {$(VPATH)}backward/2/inttypes.h
1290612910
regparse.$(OBJEXT): {$(VPATH)}backward/2/limits.h
1290712911
regparse.$(OBJEXT): {$(VPATH)}backward/2/long_long.h

include/ruby/internal/arithmetic/long.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ RB_INT2FIX(long i)
115115
/* :NOTE: VALUE can be wider than long. As j being unsigned, 2j+1 is fully
116116
* defined. Also it can be compiled into a single LEA instruction. */
117117
const unsigned long j = i;
118-
const unsigned long k = 2 * j + RUBY_FIXNUM_FLAG;
118+
const unsigned long k = (j << 1) + RUBY_FIXNUM_FLAG;
119119
const long l = k;
120120
const SIGNED_VALUE m = l; /* Sign extend */
121121
const VALUE n = m;

parse.y

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,12 @@ enum {
232232
};
233233

234234
#define NUMPARAM_ID_P(id) numparam_id_p(id)
235-
#define NUMPARAM_ID_TO_IDX(id) (unsigned int)(((id) >> ID_SCOPE_SHIFT) - tNUMPARAM_1 + 1)
236-
#define NUMPARAM_IDX_TO_ID(idx) TOKEN2LOCALID((tNUMPARAM_1 + (idx) - 1))
235+
#define NUMPARAM_ID_TO_IDX(id) (unsigned int)(((id) >> ID_SCOPE_SHIFT) - (tNUMPARAM_1 - 1))
236+
#define NUMPARAM_IDX_TO_ID(idx) TOKEN2LOCALID((tNUMPARAM_1 - 1 + (idx)))
237237
static int
238238
numparam_id_p(ID id)
239239
{
240-
if (!is_local_id(id)) return 0;
240+
if (!is_local_id(id) || id < (tNUMPARAM_1 << ID_SCOPE_SHIFT)) return 0;
241241
unsigned int idx = NUMPARAM_ID_TO_IDX(id);
242242
return idx > 0 && idx <= NUMPARAM_MAX;
243243
}

regparse.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
#include "regparse.h"
3939
#include <stdarg.h>
40+
#include "internal/sanitizers.h"
4041

4142
#define WARN_BUFSIZE 256
4243

@@ -394,6 +395,8 @@ str_end_cmp(st_data_t xp, st_data_t yp)
394395
return 0;
395396
}
396397

398+
NO_SANITIZE("unsigned-integer-overflow", static st_index_t str_end_hash(st_data_t xp));
399+
397400
static st_index_t
398401
str_end_hash(st_data_t xp)
399402
{

0 commit comments

Comments
 (0)
0