From: rsandifo Date: Tue, 15 Oct 2019 10:29:53 +0000 (+0000) Subject: Fix unchecked use of tree_to_uhwi in tree-ssa-strlen.c X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=91353f0dc7cf2304bfec7219e607b7d0ab492189;p=thirdparty%2Fgcc.git Fix unchecked use of tree_to_uhwi in tree-ssa-strlen.c r273783 introduced an unchecked use of tree_to_uhwi. This is tested by the SVE ACLE patches, but could potentially trigger in non-SVE cases too. 2019-10-15 Richard Sandiford gcc/ * tree-ssa-strlen.c (count_nonzero_bytes): Check tree_fits_uhwi_p before using tree_to_uhwi. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@276990 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 23213c75c690..bf3dbe5b08fd 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2019-10-15 Richard Sandiford + + * tree-ssa-strlen.c (count_nonzero_bytes): Check tree_fits_uhwi_p + before using tree_to_uhwi. + 2019-10-15 Ilya Leoshkevich * config/s390/s390.md: Run %a0:DI splitters only after reload. diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c index ef2717d6a29e..5b90ad3eba3a 100644 --- a/gcc/tree-ssa-strlen.c +++ b/gcc/tree-ssa-strlen.c @@ -4026,10 +4026,10 @@ count_nonzero_bytes (tree exp, unsigned HOST_WIDE_INT offset, /* The size of the MEM_REF access determines the number of bytes. */ tree type = TREE_TYPE (exp); - if (tree typesize = TYPE_SIZE_UNIT (type)) - nbytes = tree_to_uhwi (typesize); - else + tree typesize = TYPE_SIZE_UNIT (type); + if (!typesize || !tree_fits_uhwi_p (typesize)) return false; + nbytes = tree_to_uhwi (typesize); /* Handle MEM_REF = SSA_NAME types of assignments. */ return count_nonzero_bytes (arg, offset, nbytes, lenrange, nulterm,