diff mbox

PATCH: lto/55474: global-buffer-overflow in lto-wrapper.c

Message ID 20121127083212.GA1386@x4
State New
Headers show

Commit Message

Markus Trippelsdorf Nov. 27, 2012, 8:32 a.m. UTC
On 2012.11.26 at 13:58 -0800, H.J. Lu wrote:
> Hi,
> 
> OPT_SPECIAL_unknown, OPT_SPECIAL_ignore, OPT_SPECIAL_program_name and
> OPT_SPECIAL_input_file are special options, which aren't in cl_options.
> This patch avoids
> 
> if (!(cl_options[foption->opt_index].flags & CL_TARGET))
> 
> on them.  This patch skips them.  OK to install?

The same fix is necessary for gcc/lto-opts.c.
This solves the issue from PR54795 comment 5, 13 and 20.

2012-11-27  Markus Trippelsdorf  <markus@trippelsdorf.de>

	PR lto/54795
	* lto-opts.c (lto_write_options): Also handle
	OPT_SPECIAL_unknown, OPT_SPECIAL_ignore and
	OPT_SPECIAL_program_name.

Comments

Richard Biener Nov. 27, 2012, 10:07 a.m. UTC | #1
On Tue, Nov 27, 2012 at 9:32 AM, Markus Trippelsdorf
<markus@trippelsdorf.de> wrote:
> On 2012.11.26 at 13:58 -0800, H.J. Lu wrote:
>> Hi,
>>
>> OPT_SPECIAL_unknown, OPT_SPECIAL_ignore, OPT_SPECIAL_program_name and
>> OPT_SPECIAL_input_file are special options, which aren't in cl_options.
>> This patch avoids
>>
>> if (!(cl_options[foption->opt_index].flags & CL_TARGET))
>>
>> on them.  This patch skips them.  OK to install?
>
> The same fix is necessary for gcc/lto-opts.c.
> This solves the issue from PR54795 comment 5, 13 and 20.

Ok for both patches.

Thanks,
Richard.

> 2012-11-27  Markus Trippelsdorf  <markus@trippelsdorf.de>
>
>         PR lto/54795
>         * lto-opts.c (lto_write_options): Also handle
>         OPT_SPECIAL_unknown, OPT_SPECIAL_ignore and
>         OPT_SPECIAL_program_name.
>
>
> diff --git a/gcc/lto-opts.c b/gcc/lto-opts.c
> index a235f41..a61a26f 100644
> --- a/gcc/lto-opts.c
> +++ b/gcc/lto-opts.c
> @@ -93,6 +93,20 @@ lto_write_options (void)
>      {
>        struct cl_decoded_option *option = &save_decoded_options[i];
>
> +      /* Skip explicitly some common options that we do not need.  */
> +      switch (option->opt_index)
> +      {
> +       case OPT_dumpbase:
> +       case OPT_SPECIAL_unknown:
> +       case OPT_SPECIAL_ignore:
> +       case OPT_SPECIAL_program_name:
> +       case OPT_SPECIAL_input_file:
> +         continue;
> +
> +       default:
> +         break;
> +      }
> +
>        /* Skip frontend and driver specific options here.  */
>        if (!(cl_options[option->opt_index].flags & (CL_COMMON|CL_TARGET|CL_LTO)))
>         continue;
> @@ -108,17 +122,6 @@ lto_write_options (void)
>        if (cl_options[option->opt_index].flags & (CL_DRIVER|CL_WARNING))
>         continue;
>
> -      /* Skip explicitly some common options that we do not need.  */
> -      switch (option->opt_index)
> -       {
> -       case OPT_dumpbase:
> -       case OPT_SPECIAL_input_file:
> -         continue;
> -
> -       default:
> -         break;
> -       }
> -
>        for (j = 0; j < option->canonical_option_num_elements; ++j)
>         append_to_collect_gcc_options (&temporary_obstack, &first_p,
>                                        option->canonical_option[j]);
> --
> Markus
H.J. Lu Nov. 27, 2012, 9:19 p.m. UTC | #2
On Tue, Nov 27, 2012 at 2:07 AM, Richard Biener
<richard.guenther@gmail.com> wrote:
> On Tue, Nov 27, 2012 at 9:32 AM, Markus Trippelsdorf
> <markus@trippelsdorf.de> wrote:
>> On 2012.11.26 at 13:58 -0800, H.J. Lu wrote:
>>> Hi,
>>>
>>> OPT_SPECIAL_unknown, OPT_SPECIAL_ignore, OPT_SPECIAL_program_name and
>>> OPT_SPECIAL_input_file are special options, which aren't in cl_options.
>>> This patch avoids
>>>
>>> if (!(cl_options[foption->opt_index].flags & CL_TARGET))
>>>
>>> on them.  This patch skips them.  OK to install?
>>
>> The same fix is necessary for gcc/lto-opts.c.
>> This solves the issue from PR54795 comment 5, 13 and 20.
>
> Ok for both patches.
>

Fixed on trunk. The same invalid memory access exists on 4.7 branch.
OK to backport to 4.7?

Thanks.
Richard Biener Nov. 28, 2012, 10:23 a.m. UTC | #3
On Tue, Nov 27, 2012 at 10:19 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Tue, Nov 27, 2012 at 2:07 AM, Richard Biener
> <richard.guenther@gmail.com> wrote:
>> On Tue, Nov 27, 2012 at 9:32 AM, Markus Trippelsdorf
>> <markus@trippelsdorf.de> wrote:
>>> On 2012.11.26 at 13:58 -0800, H.J. Lu wrote:
>>>> Hi,
>>>>
>>>> OPT_SPECIAL_unknown, OPT_SPECIAL_ignore, OPT_SPECIAL_program_name and
>>>> OPT_SPECIAL_input_file are special options, which aren't in cl_options.
>>>> This patch avoids
>>>>
>>>> if (!(cl_options[foption->opt_index].flags & CL_TARGET))
>>>>
>>>> on them.  This patch skips them.  OK to install?
>>>
>>> The same fix is necessary for gcc/lto-opts.c.
>>> This solves the issue from PR54795 comment 5, 13 and 20.
>>
>> Ok for both patches.
>>
>
> Fixed on trunk. The same invalid memory access exists on 4.7 branch.
> OK to backport to 4.7?

Yes, of course.

Thanks,
Richard.

> Thanks.
>
> --
> H.J.
diff mbox

Patch

diff --git a/gcc/lto-opts.c b/gcc/lto-opts.c
index a235f41..a61a26f 100644
--- a/gcc/lto-opts.c
+++ b/gcc/lto-opts.c
@@ -93,6 +93,20 @@  lto_write_options (void)
     {
       struct cl_decoded_option *option = &save_decoded_options[i];
 
+      /* Skip explicitly some common options that we do not need.  */
+      switch (option->opt_index)
+      {
+	case OPT_dumpbase:
+	case OPT_SPECIAL_unknown:
+	case OPT_SPECIAL_ignore:
+	case OPT_SPECIAL_program_name:
+	case OPT_SPECIAL_input_file:
+	  continue;
+
+	default:
+	  break;
+      }
+
       /* Skip frontend and driver specific options here.  */
       if (!(cl_options[option->opt_index].flags & (CL_COMMON|CL_TARGET|CL_LTO)))
 	continue;
@@ -108,17 +122,6 @@  lto_write_options (void)
       if (cl_options[option->opt_index].flags & (CL_DRIVER|CL_WARNING))
 	continue;
 
-      /* Skip explicitly some common options that we do not need.  */
-      switch (option->opt_index)
-	{
-	case OPT_dumpbase:
-	case OPT_SPECIAL_input_file:
-	  continue;
-
-	default:
-	  break;
-	}
-
       for (j = 0; j < option->canonical_option_num_elements; ++j)
 	append_to_collect_gcc_options (&temporary_obstack, &first_p,
 				       option->canonical_option[j]);