public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Nick Clifton <nickc@redhat.com>
To: gcc-patches@gcc.gnu.org
Subject: Libiberty: Infinite recursive loop in @FILE option
Date: Thu, 12 Aug 2010 13:42:00 -0000	[thread overview]
Message-ID: <m3lj8c54s8.fsf@redhat.com> (raw)

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)

             reply	other threads:[~2010-08-12 13:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-12 13:42 Nick Clifton [this message]
2010-08-12 17:15 ` DJ Delorie
2010-08-13 11:59   ` Nick Clifton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3lj8c54s8.fsf@redhat.com \
    --to=nickc@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).