This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Libiberty: Infinite recursive loop in @FILE option


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)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]