diff mbox

PATCH: PR binutils/14526: c++filt is crashed on large files

Message ID 20120828183347.GA5331@intel.com
State New
Headers show

Commit Message

H.J. Lu Aug. 28, 2012, 6:33 p.m. UTC
Hi,

buildargv uses alloca to allocate buffer, whose size may exceed stack
limit.  This patch replaces alloca with xmalloc/free.  OK to install?

Thanks.

H.J.
---
	PR binutils/14526
	* argv.c (buildargv): Replace alloca with xmalloc/free.

Comments

Ian Lance Taylor Aug. 29, 2012, 12:09 a.m. UTC | #1
On Tue, Aug 28, 2012 at 11:33 AM, H.J. Lu <hongjiu.lu@intel.com> wrote:
>
> buildargv uses alloca to allocate buffer, whose size may exceed stack
> limit.  This patch replaces alloca with xmalloc/free.  OK to install?
>
> Thanks.
>
> H.J.
> ---
>         PR binutils/14526
>         * argv.c (buildargv): Replace alloca with xmalloc/free.

This is OK.

Thanks.

Consider also replacing strdup with xstrdup.  And there are other
malloc calls that could become xmalloc.  I can't think of any way that
this code would be used where it needs to degrade gracefully when
short on memory.

Ian
diff mbox

Patch

diff --git a/libiberty/argv.c b/libiberty/argv.c
index ca53f91..4cef3bc 100644
--- a/libiberty/argv.c
+++ b/libiberty/argv.c
@@ -191,7 +191,7 @@  char **buildargv (const char *input)
 
   if (input != NULL)
     {
-      copybuf = (char *) alloca (strlen (input) + 1);
+      copybuf = (char *) xmalloc (strlen (input) + 1);
       /* Is a do{}while to always execute the loop once.  Always return an
 	 argv, even for null strings.  See NOTES above, test case below. */
       do
@@ -297,6 +297,8 @@  char **buildargv (const char *input)
 	  consume_whitespace (&input);
 	}
       while (*input != EOS);
+
+      free (copybuf);
     }
   return (argv);
 }