* [PATCH] Plug possible snprintf overflow in lto-wrapper.
@ 2021-09-30 6:16 Aldy Hernandez
2021-09-30 7:44 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: Aldy Hernandez @ 2021-09-30 6:16 UTC (permalink / raw)
To: GCC patches
My upcoming improvements to the DOM threader triggered a warning in
this code. It looks like the format string is ".ltrans%u.ltrans", but
we're only writing a max of ".ltrans" + whatever the MAX_INT is here.
Tested on x86-64 Linux.
OK?
gcc/ChangeLog:
* lto-wrapper.c (run_gcc): Plug snprintf overflow.
---
gcc/lto-wrapper.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/gcc/lto-wrapper.c b/gcc/lto-wrapper.c
index 903c258a03a..7b9e4883f38 100644
--- a/gcc/lto-wrapper.c
+++ b/gcc/lto-wrapper.c
@@ -1983,7 +1983,9 @@ cont:
output_name = XOBFINISH (&env_obstack, char *);
/* Adjust the dumpbase if the linker output file was seen. */
- int dumpbase_len = (strlen (dumppfx) + sizeof (DUMPBASE_SUFFIX));
+ int dumpbase_len = (strlen (dumppfx)
+ + sizeof (DUMPBASE_SUFFIX)
+ + sizeof (".ltrans"));
char *dumpbase = (char *) xmalloc (dumpbase_len + 1);
snprintf (dumpbase, dumpbase_len, "%sltrans%u.ltrans", dumppfx, i);
argv_ptr[0] = dumpbase;
@@ -2009,9 +2011,11 @@ cont:
}
else
{
- char argsuffix[sizeof (DUMPBASE_SUFFIX) + 1];
+ char argsuffix[sizeof (DUMPBASE_SUFFIX)
+ + sizeof (".ltrans_args") + 1];
if (save_temps)
- snprintf (argsuffix, sizeof (DUMPBASE_SUFFIX),
+ snprintf (argsuffix,
+ sizeof (DUMPBASE_SUFFIX) + sizeof (".ltrans_args"),
"ltrans%u.ltrans_args", i);
fork_execute (new_argv[0], CONST_CAST (char **, new_argv),
true, save_temps ? argsuffix : NULL);
--
2.31.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Plug possible snprintf overflow in lto-wrapper.
2021-09-30 6:16 [PATCH] Plug possible snprintf overflow in lto-wrapper Aldy Hernandez
@ 2021-09-30 7:44 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2021-09-30 7:44 UTC (permalink / raw)
To: Aldy Hernandez; +Cc: GCC patches
On Thu, Sep 30, 2021 at 8:17 AM Aldy Hernandez via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> My upcoming improvements to the DOM threader triggered a warning in
> this code. It looks like the format string is ".ltrans%u.ltrans", but
> we're only writing a max of ".ltrans" + whatever the MAX_INT is here.
>
> Tested on x86-64 Linux.
>
> OK?
OK. Note that %u is max 127 by default (--param lto-partitions).
Richard.
> gcc/ChangeLog:
>
> * lto-wrapper.c (run_gcc): Plug snprintf overflow.
> ---
> gcc/lto-wrapper.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/gcc/lto-wrapper.c b/gcc/lto-wrapper.c
> index 903c258a03a..7b9e4883f38 100644
> --- a/gcc/lto-wrapper.c
> +++ b/gcc/lto-wrapper.c
> @@ -1983,7 +1983,9 @@ cont:
> output_name = XOBFINISH (&env_obstack, char *);
>
> /* Adjust the dumpbase if the linker output file was seen. */
> - int dumpbase_len = (strlen (dumppfx) + sizeof (DUMPBASE_SUFFIX));
> + int dumpbase_len = (strlen (dumppfx)
> + + sizeof (DUMPBASE_SUFFIX)
> + + sizeof (".ltrans"));
> char *dumpbase = (char *) xmalloc (dumpbase_len + 1);
> snprintf (dumpbase, dumpbase_len, "%sltrans%u.ltrans", dumppfx, i);
> argv_ptr[0] = dumpbase;
> @@ -2009,9 +2011,11 @@ cont:
> }
> else
> {
> - char argsuffix[sizeof (DUMPBASE_SUFFIX) + 1];
> + char argsuffix[sizeof (DUMPBASE_SUFFIX)
> + + sizeof (".ltrans_args") + 1];
> if (save_temps)
> - snprintf (argsuffix, sizeof (DUMPBASE_SUFFIX),
> + snprintf (argsuffix,
> + sizeof (DUMPBASE_SUFFIX) + sizeof (".ltrans_args"),
> "ltrans%u.ltrans_args", i);
> fork_execute (new_argv[0], CONST_CAST (char **, new_argv),
> true, save_temps ? argsuffix : NULL);
> --
> 2.31.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-09-30 7:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-30 6:16 [PATCH] Plug possible snprintf overflow in lto-wrapper Aldy Hernandez
2021-09-30 7:44 ` Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).