This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix UB in tree-ssa-structalias.c


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]