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] gcc/ubsan.c: Extend 'pretty_name' space to avoid memory overflow


On 11/17/14 18:52, Chen Gang wrote:
> 
> What you said sound reasonable to me.
> 
> I shall try to send patch v2 within this week (use pretty_printer).
> 
> Thanks.
> 
> On 11/17/14 16:15, Marek Polacek wrote:
>> On Mon, Nov 17, 2014 at 08:38:19AM +0100, Jakub Jelinek wrote:
>>
>>> I think easiest would be to rewrite the code so that it uses pretty_printer
>>> to construct the string, grep asan.c for asan_pp .  Or obstacks, but you don't
>>> have a printer to print integers into it easily.
>>>           if (dom && TREE_CODE (TYPE_MAX_VALUE (dom)) == INTEGER_CST)
>>>             pos += sprintf (&pretty_name[pos], HOST_WIDE_INT_PRINT_DEC,
>>>                             tree_to_uhwi (TYPE_MAX_VALUE (dom)) + 1);
>>>           else
>>>             /* ??? We can't determine the variable name; print VLA unspec.  */
>>>             pretty_name[pos++] = '*';
>>> looks wrong anyway, as not all integers fit into uhwi.
>>> Guess you could use wide_int to add 1 there and pp_wide_int.

I have finish use pretty_print instead of normal sprintf, but for above
case, after I tried to use wide_int, it can not pass testsuite, please
help check whether what I have done is correct or not:

For "make check-gcc RUNTESTFLAGS=ubsan.exp".

 - Simply replace is OK:

            pp_printf (&pretty_name, HOST_WIDE_INT_PRINT_DEC,
                            tree_to_uhwi (TYPE_MAX_VALUE (dom)) + 1);

 - But use pp_wide_int for wide_int, will cause issue:

            pp_wide_int(&pretty_name, wi::add (wi::max_value (dom), 1),
                        TYPE_SIGN (TREE_TYPE (dom)));

 - The related issues are:

   Running /upstream/gcc-new-x86/gcc/testsuite/gcc.dg/ubsan/ubsan.exp ...
   FAIL: c-c++-common/ubsan/bounds-2.c   -O0  output pattern test
   FAIL: c-c++-common/ubsan/bounds-2.c   -O1  output pattern test
   FAIL: c-c++-common/ubsan/bounds-2.c   -O2  output pattern test
   FAIL: c-c++-common/ubsan/bounds-2.c   -O3 -fomit-frame-pointer  output pattern test
   FAIL: c-c++-common/ubsan/bounds-2.c   -O3 -fomit-frame-pointer -funroll-loops  output pattern test
   FAIL: c-c++-common/ubsan/bounds-2.c   -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions  output pattern test
   FAIL: c-c++-common/ubsan/bounds-2.c   -O3 -g  output pattern test
   FAIL: c-c++-common/ubsan/bounds-2.c   -Os  output pattern test
   FAIL: c-c++-common/ubsan/bounds-2.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  output pattern test
   FAIL: c-c++-common/ubsan/bounds-2.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  output pattern test
   FAIL: c-c++-common/ubsan/bounds-5.c   -O0  output pattern test
   FAIL: c-c++-common/ubsan/bounds-5.c   -O1  output pattern test
   FAIL: c-c++-common/ubsan/bounds-5.c   -O2  output pattern test
   FAIL: c-c++-common/ubsan/bounds-5.c   -O3 -fomit-frame-pointer  output pattern test
   FAIL: c-c++-common/ubsan/bounds-5.c   -O3 -fomit-frame-pointer -funroll-loops  output pattern test
   FAIL: c-c++-common/ubsan/bounds-5.c   -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions  output pattern test
   FAIL: c-c++-common/ubsan/bounds-5.c   -O3 -g  output pattern test
   FAIL: c-c++-common/ubsan/bounds-5.c   -Os  output pattern test
   FAIL: c-c++-common/ubsan/bounds-5.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  output pattern test
   FAIL: c-c++-common/ubsan/bounds-5.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  output pattern test
   FAIL: c-c++-common/ubsan/bounds-7.c   -O0  output pattern test
   FAIL: c-c++-common/ubsan/bounds-7.c   -O1  output pattern test
   FAIL: c-c++-common/ubsan/bounds-7.c   -O2  output pattern test
   FAIL: c-c++-common/ubsan/bounds-7.c   -O3 -fomit-frame-pointer  output pattern test
   FAIL: c-c++-common/ubsan/bounds-7.c   -O3 -fomit-frame-pointer -funroll-loops  output pattern test
   FAIL: c-c++-common/ubsan/bounds-7.c   -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions  output pattern test
   FAIL: c-c++-common/ubsan/bounds-7.c   -O3 -g  output pattern test
   FAIL: c-c++-common/ubsan/bounds-7.c   -Os  output pattern test
   FAIL: c-c++-common/ubsan/bounds-7.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  output pattern test
   FAIL: c-c++-common/ubsan/bounds-7.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  output pattern test


Thanks.
-- 
Chen Gang

Open, share, and attitude like air, water, and life which God blessed


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