[PATCH] Do not strcat to result of getenv.
Jakub Jelinek
jakub@redhat.com
Fri Mar 13 12:39:55 GMT 2020
On Fri, Mar 13, 2020 at 01:26:02PM +0100, Martin Liška wrote:
> diff --git a/gcc/lto-wrapper.c b/gcc/lto-wrapper.c
> index b8a35c85714..84a0bd24e91 100644
> --- a/gcc/lto-wrapper.c
> +++ b/gcc/lto-wrapper.c
> @@ -1317,7 +1317,11 @@ run_gcc (unsigned argc, char *argv[])
>
> char *xassembler_opts_string
> = XOBFINISH (&temporary_obstack, char *);
> - strcat (collect_gcc_options, xassembler_opts_string);
> + char *collect = (char *)xmalloc (strlen (collect_gcc_options)
> + + strlen (xassembler_opts_string) + 1);
> + strcpy (collect, collect_gcc_options);
> + strcat (collect, xassembler_opts_string);
collect_gcc_options = concat (collect_gcc_options,
xassembler_opts_string, NULL);
instead?
Though, even that looks like a memory leak.
So, e.g. record that collect_gcc_options has been allocated in some bool
and XDELETE it at the end of function?
The string could be as well built in the temporary_obstack by
obstack_grow (&temporary_obstack, collect_gcc_options);
before the prepend_xassembler_to_collect_as_options call (which btw seems
incorrectly formatted, the function name should be at the start of line),
but you'd then need to finish the obstack at the end of function.
> + collect_gcc_options = collect;
Jakub
More information about the Gcc-patches
mailing list