* [PATCH] Fix UB in tree-ssa-structalias.c
@ 2017-06-19 17:46 Jakub Jelinek
2017-06-19 17:51 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2017-06-19 17:46 UTC (permalink / raw)
To: Richard Biener; +Cc: gcc-patches
Hi!
Another easy to fix bug reported by bootstrap-ubsan.
We check that rhsunitoffset fits into shwi, but even if it does,
8x that might not, in which case we trigger UB.
Fixed by doing the multiplication in unsigned HWI type to make it well
defined.
Bootstrapped/regtested on x86_64-linux and i686-linux (both normal
and bootstrap-ubsan), ok for trunk?
2017-06-19 Jakub Jelinek <jakub@redhat.com>
* tree-ssa-structalias.c (get_constraint_for_ptr_offset): Multiply
in UWHI to avoid undefined overflow.
--- gcc/tree-ssa-structalias.c.jj 2017-05-24 11:59:06.000000000 +0200
+++ gcc/tree-ssa-structalias.c 2017-06-19 14:10:50.989594911 +0200
@@ -3087,7 +3087,7 @@ get_constraint_for_ptr_offset (tree ptr,
{
/* Make sure the bit-offset also fits. */
HOST_WIDE_INT rhsunitoffset = soffset.to_shwi ();
- rhsoffset = rhsunitoffset * BITS_PER_UNIT;
+ rhsoffset = rhsunitoffset * (unsigned HOST_WIDE_INT) BITS_PER_UNIT;
if (rhsunitoffset != rhsoffset / BITS_PER_UNIT)
rhsoffset = UNKNOWN_OFFSET;
}
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Fix UB in tree-ssa-structalias.c
2017-06-19 17:46 [PATCH] Fix UB in tree-ssa-structalias.c Jakub Jelinek
@ 2017-06-19 17:51 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2017-06-19 17:51 UTC (permalink / raw)
To: Jakub Jelinek, Richard Biener; +Cc: gcc-patches
On June 19, 2017 7:46:03 PM GMT+02:00, Jakub Jelinek <jakub@redhat.com> wrote:
>Hi!
>
>Another easy to fix bug reported by bootstrap-ubsan.
>We check that rhsunitoffset fits into shwi, but even if it does,
>8x that might not, in which case we trigger UB.
>Fixed by doing the multiplication in unsigned HWI type to make it well
>defined.
>
>Bootstrapped/regtested on x86_64-linux and i686-linux (both normal
>and bootstrap-ubsan), ok for trunk?
OK.
Richard.
>2017-06-19 Jakub Jelinek <jakub@redhat.com>
>
> * tree-ssa-structalias.c (get_constraint_for_ptr_offset): Multiply
> in UWHI to avoid undefined overflow.
>
>--- gcc/tree-ssa-structalias.c.jj 2017-05-24 11:59:06.000000000 +0200
>+++ gcc/tree-ssa-structalias.c 2017-06-19 14:10:50.989594911 +0200
>@@ -3087,7 +3087,7 @@ get_constraint_for_ptr_offset (tree ptr,
> {
> /* Make sure the bit-offset also fits. */
> HOST_WIDE_INT rhsunitoffset = soffset.to_shwi ();
>- rhsoffset = rhsunitoffset * BITS_PER_UNIT;
>+ rhsoffset = rhsunitoffset * (unsigned HOST_WIDE_INT) BITS_PER_UNIT;
> if (rhsunitoffset != rhsoffset / BITS_PER_UNIT)
> rhsoffset = UNKNOWN_OFFSET;
> }
>
> Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-06-19 17:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-19 17:46 [PATCH] Fix UB in tree-ssa-structalias.c Jakub Jelinek
2017-06-19 17:51 ` Richard Biener
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).