* UBSan fix: avoid undefined behaviour in bitmask
@ 2014-03-28 17:39 Andrew Haley
0 siblings, 0 replies; only message in thread
From: Andrew Haley @ 2014-03-28 17:39 UTC (permalink / raw)
To: GCC Patches, GCJ-patches; +Cc: Jakub Jelinek
UBSan detected that we were trying to set a non-existent bit in a mask.
I don't think it has mattered before now because when this happens the
value in the mask is not used. However, better safe than sorry.
Andrew.
2014-03-28 Andrew Haley <aph@redhat.com>
* boehm.c (mark_reference_fields): Avoid unsigned integer overflow
when calculating an index into a bitmap descriptor.
Index: gcc/java/boehm.c
===================================================================
--- gcc/java/boehm.c (revision 208839)
+++ gcc/java/boehm.c (working copy)
@@ -107,7 +107,11 @@
bits for all words in the record. This is conservative, but the
size_words != 1 case is impossible in regular java code. */
for (i = 0; i < size_words; ++i)
- *mask = (*mask).set_bit (ubit - count - i - 1);
+ {
+ int bitpos = ubit - count - i - 1;
+ if (bitpos >= 0)
+ *mask = (*mask).set_bit (bitpos);
+ }
if (count >= ubit - 2)
*pointer_after_end = 1;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2014-03-28 17:39 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-28 17:39 UBSan fix: avoid undefined behaviour in bitmask Andrew Haley
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).