automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FYI: Debian Bug#162583: Automake causes Perl to overuse stack space


From: Alexandre Duret-Lutz
Subject: FYI: Debian Bug#162583: Automake causes Perl to overuse stack space
Date: 08 Oct 2002 23:39:42 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

"Sam Hocevar" <address@hidden> writes:
| Package: automake1.6
| Version: 1.6.3-2
| Severity: normal
| Tags: upstream patch
| 
|    automake-1.6 uses a suboptimal Perl regexp around line 7554:
| 
|           # I'm quite shoked!  It seems that (\\\n|[^\n]) is not the
|           # same as `([^\n]|\\\n)!!!  Don't swap it, it
|           # breaks.
|           my $paragraph = $_;
|           /^((?:\\\n|[^\n])*)(?:\n(\t.*))?$/som;
| 
|    This makes Perl segfault with very long lines (see below). I suggest
| the following instead:
| 
|           my $paragraph = $_;
|           /^((?:[^\\\n]*(?:\\\n)?)*)(?:\n(\t.*))?$/som;
| 
|    You can also remove the comment just above. Anyone understanding
| regexp greediness should know why (\\\n|[^\n]) and ([^\n]|\\\n) aren't
| the same, and my patch gets rid of this anyway.
| 
|    Here is a text case which triggers the bug:
| 
|      should segfault: perl -e '("X" x 100000) =~ /^((?:AB|[^B])*)$/'
| 
|      works:           perl -e '("X" x 100000) =~ /^(?:([^AB]*(?:AB)?)*)$/'

Wow!  Thanks for catching this.  How did you find this?  This
statement is only used while reading Automake's fragements, not
user Makefile.ams (yet).

However your new regex isn't equivalent to the old if you
consider backslashes in the middle of lines.  This is probably
easier to see on the cut-down test case:

% perl -e 'print "CCACAB" =~ /^((?:AB|[^B])*)$/, ".\n"'
CCACAB.
% perl -e 'print "CCACAB" =~ /^(?:([^AB]*(?:AB)?)*)$/, ".\n"'
.

Of course if we rewrite this as /^(?:([^B]*(?:AB)?)*)$/, it breaks
for the same reason ([^\n]|\\\n)* did and (\\\n|[^\n])* didn't.


But, well, let's ignore this complicated regex.  What we really
want here is to split at the first new-line not preceded by a
backslash, and perl's regexes can express this straight.

I'm installing the following patch on HEAD and branch-1-7.  This
will be in Automake 1.7.1.

2002-10-08  Alexandre Duret-Lutz  <address@hidden>

        For Debian Bug#162583:
        * automake.in (file_contents_internal): Simplify regex to
        separate relationship from actions in rules.
        Reported by Sam Hocevar.

Index: THANKS
===================================================================
RCS file: /cvs/automake/automake/THANKS,v
retrieving revision 1.189
diff -u -r1.189 THANKS
--- THANKS      1 Oct 2002 19:59:32 -0000       1.189
+++ THANKS      8 Oct 2002 21:07:37 -0000
@@ -174,6 +174,7 @@
 Robert Collins         address@hidden
 Rusty Ballinger                address@hidden
 Ryan T. Sammartino     address@hidden
+Sam Hocevar            address@hidden
 Sergey Vlasov          address@hidden
 Seth Alves             address@hidden
 Shuhei Amakawa         <address@hidden>
Index: automake.in
===================================================================
RCS file: /cvs/automake/automake/automake.in,v
retrieving revision 1.1375
diff -u -r1.1375 automake.in
--- automake.in 7 Oct 2002 09:23:31 -0000       1.1375
+++ automake.in 8 Oct 2002 21:08:04 -0000
@@ -8163,10 +8163,8 @@
          # Separate relationship from optional actions: the first
          # `new-line tab" not preceded by backslash (continuation
          # line).
-         # I'm quite shoked!  It seems that (\\\n|[^\n]) is not the
-         # same as `([^\n]|\\\n)!!!  Don't swap it, it breaks.
          my $paragraph = $_;
-         /^((?:\\\n|[^\n])*)(?:\n(\t.*))?$/som;
+         /^(.*?)(?:(?<!\\)\n(\t.*))?$/som;
          my ($relationship, $actions) = ($1, $2 || '');
 
          # Separate targets from dependencies: the first colon.

-- 
Alexandre Duret-Lutz





reply via email to

[Prev in Thread] Current Thread [Next in Thread]