This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] gcc/ubsan.c: Extend 'pretty_name' space to avoid memory overflow
- From: Chen Gang <gang dot chen dot 5i5j at gmail dot com>
- To: Marek Polacek <polacek at redhat dot com>, Jakub Jelinek <jakub at redhat dot com>
- Cc: Jeff Law <law at redhat dot com>, "Joseph S. Myers" <joseph at codesourcery dot com>, rth at redhat dot com, gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 20 Nov 2014 23:17:47 +0800
- Subject: Re: [PATCH] gcc/ubsan.c: Extend 'pretty_name' space to avoid memory overflow
- Authentication-results: sourceware.org; auth=none
- References: <546927DA dot 4000804 at gmail dot com> <20141117071632 dot GC14744 at redhat dot com> <20141117073819 dot GB4079 at tucnak dot redhat dot com> <20141117081531 dot GD14744 at redhat dot com> <5469D373 dot 4050704 at gmail dot com>
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