[gcc(refs/users/marxin/heads/PR94157-lto-wrapper-strcat)] Do not strcat to result of getenv.

Martin Liska marxin@gcc.gnu.org
Thu Mar 12 18:57:53 GMT 2020


https://gcc.gnu.org/g:5d952ae53c64c9d37a85513b6499d41b30ab4478

commit 5d952ae53c64c9d37a85513b6499d41b30ab4478
Author: Martin Liska <mliska@suse.cz>
Date:   Thu Mar 12 19:56:47 2020 +0100

    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): 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.

Diff:
---
 gcc/lto-wrapper.c                    | 6 +++++-
 gcc/testsuite/gcc.dg/lto/pr94157_0.c | 6 ++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

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() {
+
+}


More information about the Gcc-cvs mailing list