public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Libiberty: Infinite recursive loop in @FILE option
@ 2010-08-12 13:42 Nick Clifton
  2010-08-12 17:15 ` DJ Delorie
  0 siblings, 1 reply; 3+ messages in thread
From: Nick Clifton @ 2010-08-12 13:42 UTC (permalink / raw)
  To: gcc-patches

Hi Guys,

  Binutils bug #11835 is actually a libiberty bug in the handling of
  command lines containing recursive @<file> directives:

    http://sourceware.org/bugzilla/show_bug.cgi?id=11835

  A simple iteration count is one way to solve the problem, so I have
  appended a suggested patch below.  I am not sure however if the limit
  of 2000 iterations would be regarded as being too small.

  OK to apply ?

Cheers
  Nick

libiberty/ChangeLog
2010-08-12  Nick Clifton  <nickc@redhat.com>

	* argv.c (expandargv): Limit the number of times that response
	files are opened in order to prevent infinite recursion.

Index: libiberty/argv.c
===================================================================
RCS file: /cvs/src/src/libiberty/argv.c,v
retrieving revision 1.21
diff -c -3 -p -r1.21 argv.c
*** libiberty/argv.c	9 Oct 2009 04:49:48 -0000	1.21
--- libiberty/argv.c	12 Aug 2010 13:38:14 -0000
*************** expandargv (int *argcp, char ***argvp)
*** 386,391 ****
--- 386,394 ----
    int i = 0;
    /* Non-zero if ***argvp has been dynamically allocated.  */
    int argv_dynamic = 0;
+   /* Limit the number of response files that we parse in order
+      to prevent infinite recursion.  */
+   unsigned int iteration_limit = 2000;
    /* Loop over the arguments, handling response files.  We always skip
       ARGVP[0], as that is the name of the program being run.  */
    while (++i < *argcp)
*************** expandargv (int *argcp, char ***argvp)
*** 412,417 ****
--- 415,426 ----
        filename = (*argvp)[i];
        if (filename[0] != '@')
  	continue;
+       /* If we have iterated too many times then stop.  */
+       if (-- iteration_limit == 0)
+ 	{
+ 	  fprintf (stderr, "%s: error: too many @-files encountered\n", (*argvp)[0]);
+ 	  xexit (1);
+ 	}
        /* Read the contents of the file.  */
        f = fopen (++filename, "r");
        if (!f)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-08-13 11:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-12 13:42 Libiberty: Infinite recursive loop in @FILE option Nick Clifton
2010-08-12 17:15 ` DJ Delorie
2010-08-13 11:59   ` Nick Clifton

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