* [PATCH] Do not strcat to result of getenv.
@ 2020-03-13 12:26 Martin Liška
2020-03-13 12:39 ` Jakub Jelinek
0 siblings, 1 reply; 3+ messages in thread
From: Martin Liška @ 2020-03-13 12:26 UTC (permalink / raw)
To: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 684 bytes --]
Hi.
The patch fixed wrong strcat to a char pointer received
with getenv.
Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
Ready to be installed?
Thanks,
Martin
gcc/ChangeLog:
2020-03-12 Martin Liska <mliska@suse.cz>
PR lto/94157
* lto-wrapper.c (run_gcc): Allocate a new buffer.
Do not strcat to result of getenv.
gcc/testsuite/ChangeLog:
2020-03-12 Martin Liska <mliska@suse.cz>
PR lto/94157
* gcc.dg/lto/pr94157_0.c: New test.
---
gcc/lto-wrapper.c | 6 +++++-
gcc/testsuite/gcc.dg/lto/pr94157_0.c | 6 ++++++
2 files changed, 11 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.dg/lto/pr94157_0.c
[-- Attachment #2: 0001-Do-not-strcat-to-result-of-getenv.patch --]
[-- Type: text/x-patch, Size: 1256 bytes --]
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 = collect;
}
get_options_from_collect_gcc_options (collect_gcc, collect_gcc_options,
diff --git a/gcc/testsuite/gcc.dg/lto/pr94157_0.c b/gcc/testsuite/gcc.dg/lto/pr94157_0.c
new file mode 100644
index 00000000000..3bca677c4fb
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/lto/pr94157_0.c
@@ -0,0 +1,6 @@
+/* { dg-lto-do link } */
+/* { dg-lto-options { { -O0 -fipa-vrp -flto -Wa,--noexecstack -Wa,--noexecstack -Wa,--execstack -Wa,--execstack -Wa,--execstack -Wa,--execstack -Wa,--execstack -Wa,--execstack -Wa,--execstack -Wa,--execstack -Wa,--execstack -Wa,--execstack -Wa,--execstack -Wa,--execstack -Wa,--execstack -Wa,--execstack } } } */
+
+int main() {
+
+}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Do not strcat to result of getenv.
2020-03-13 12:26 [PATCH] Do not strcat to result of getenv Martin Liška
@ 2020-03-13 12:39 ` Jakub Jelinek
2020-03-13 12:48 ` Martin Liška
0 siblings, 1 reply; 3+ messages in thread
From: Jakub Jelinek @ 2020-03-13 12:39 UTC (permalink / raw)
To: Martin Liška; +Cc: gcc-patches
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Do not strcat to result of getenv.
2020-03-13 12:39 ` Jakub Jelinek
@ 2020-03-13 12:48 ` Martin Liška
0 siblings, 0 replies; 3+ messages in thread
From: Martin Liška @ 2020-03-13 12:48 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 301 bytes --]
On 3/13/20 1:39 PM, Jakub Jelinek wrote:
> collect_gcc_options = concat (collect_gcc_options,
> xassembler_opts_string, NULL);
> instead?
Ah, I forgot that concat is available here. I would choose
this way, even though it's a small memory leak.
I'm going to install the patch.
Martin
[-- Attachment #2: 0001-Do-not-strcat-to-result-of-getenv.patch --]
[-- Type: text/x-patch, Size: 1788 bytes --]
From 4f287d2b028b61b47f4d8cec7b7db14636122653 Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Thu, 12 Mar 2020 19:56:47 +0100
Subject: [PATCH] Do not strcat to result of getenv.
gcc/ChangeLog:
2020-03-12 Martin Liska <mliska@suse.cz>
PR lto/94157
* lto-wrapper.c (run_gcc): Use concat for appending
to collect_gcc_options.
gcc/testsuite/ChangeLog:
2020-03-12 Martin Liska <mliska@suse.cz>
PR lto/94157
* gcc.dg/lto/pr94157_0.c: New test.
---
gcc/lto-wrapper.c | 3 ++-
gcc/testsuite/gcc.dg/lto/pr94157_0.c | 6 ++++++
2 files changed, 8 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.dg/lto/pr94157_0.c
diff --git a/gcc/lto-wrapper.c b/gcc/lto-wrapper.c
index b8a35c85714..46a88b233f6 100644
--- a/gcc/lto-wrapper.c
+++ b/gcc/lto-wrapper.c
@@ -1317,7 +1317,8 @@ run_gcc (unsigned argc, char *argv[])
char *xassembler_opts_string
= XOBFINISH (&temporary_obstack, char *);
- strcat (collect_gcc_options, xassembler_opts_string);
+ collect_gcc_options = concat (collect_gcc_options, xassembler_opts_string,
+ NULL);
}
get_options_from_collect_gcc_options (collect_gcc, collect_gcc_options,
diff --git a/gcc/testsuite/gcc.dg/lto/pr94157_0.c b/gcc/testsuite/gcc.dg/lto/pr94157_0.c
new file mode 100644
index 00000000000..3bca677c4fb
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/lto/pr94157_0.c
@@ -0,0 +1,6 @@
+/* { dg-lto-do link } */
+/* { dg-lto-options { { -O0 -fipa-vrp -flto -Wa,--noexecstack -Wa,--noexecstack -Wa,--execstack -Wa,--execstack -Wa,--execstack -Wa,--execstack -Wa,--execstack -Wa,--execstack -Wa,--execstack -Wa,--execstack -Wa,--execstack -Wa,--execstack -Wa,--execstack -Wa,--execstack -Wa,--execstack -Wa,--execstack } } } */
+
+int main() {
+
+}
--
2.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-03-13 12:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-13 12:26 [PATCH] Do not strcat to result of getenv Martin Liška
2020-03-13 12:39 ` Jakub Jelinek
2020-03-13 12:48 ` Martin Liška
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).