From: Dominic Dunlop Date: Mon, 22 Jun 1998 15:22:24 +0000 (+0000) Subject: Amend tests/regexp.t for variable REG_INFTY; X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=83e898de4c33570d7f7c201c6f693bc6bd7ed922;p=p5sagit%2Fp5-mst-13.2.git Amend tests/regexp.t for variable REG_INFTY; Message-Id: update machten.sh to vary REG_INFTY p4raw-id: //depot/perl@1195 --- diff --git a/hints/machten.sh b/hints/machten.sh index 2ae79f1..2485460 100644 --- a/hints/machten.sh +++ b/hints/machten.sh @@ -13,6 +13,8 @@ # Martijn Koster # Richard Yeh # +# Raise perl's stack size again; cut down reg_infty; document +# -- Dominic Dunlop 980619 # Use of semctl() can crash system: disable -- Dominic Dunlop 980506 # Raise stack size further; slight tweaks to accomodate MT 4.1 # -- Dominic Dunlop 980211 @@ -37,10 +39,61 @@ usemymalloc='false' # Make symbol table listings les voluminous nmopts=-gp -# Increase perl's stack size. Without this, lib/complex.t crashes out. -# Particularly perverse programs may require that perl has an even larger -# stack allocation than that specified here. (See man setstackspace ) -ldflags='-Xlstack=0x018000' +# Set reg_infty -- the maximum allowable number of repeats in regular +# expressions such as /a{1,$max_repeats}/, and the maximum number of +# times /a*/ will match. Setting this too high without having a stack +# large enough to accommodate deep recursion in the regular expression +# engine allows perl to crash your Mac due to stack overrun if it +# encounters a pathological regular expression. The default is a +# compromise between capability and required stack size (see below). +# You may override the default value from the Configure command-line +# like this: +# +# Configure -Dreg_infty=16368 ... + +reg_infty=${reg_infty:-2047} + +# If you want to have many perl processes active simultaneously -- +# processing CGI forms -- for example, you should opt for a small stack. +# For safety, you should set reg_infty no larger than the corresponding +# value given in this table: +# +# Stack size reg_infty value supported +# ---------- ------------------------- +# 128k 2**8-1 (256) +# 256k 2**9-1 (511) +# 512k 2**10-1 (1023) +# 1M 2**11-1 (2047) +# ... +# 16M 2**15-1 (32767) (perl's default value) + +# This script selects a safe stack size based on the value of reg_infty +# specified above. However, you may choose to take a risk and set +# stack size lower: pathological regular expressions are rare in real-world +# programs. But be aware that, if perl does encounter one, it WILL +# crash your system. Do not set stack size lower than 96k unless +# you want perl's installation tests ( make test ) to crash your system. +# +# You may override the default value from the Configure command-line +# by specifying the required size in kilobytes like this: +# +# Configure -Dstack_size=96 + +if [ "X$stack_size" = 'X' ] +then + stack_size=128 + X=`expr $reg_infty / 256` + + while [ $X -gt 0 ] + do + X=`expr $X / 2` + stack_size=`expr $stack_size \* 2` + done +fi + +X=`expr $stack_size \* 1024` +ldflags="$ldflags -Xlstack=$X" +ccflags="$ccflags -DREG_INFTY=$reg_infty" # Install in /usr/local by default prefix='/usr/local' @@ -77,12 +130,12 @@ libswanted="$*" # Propagating recommended variable dont_use_nlink dont_use_nlink=define -cat <<'EOM' >&4 +cat <&4 During Configure, you may see the message *** WHOA THERE!!! *** - The recommended value for $d_semctl on this machine was "undef"! + The recommended value for \$d_semctl on this machine was "undef"! Keep the recommended value? [y] Select the default answer: semctl() is buggy, and perl should be built @@ -93,8 +146,13 @@ At the end of Configure, you will see a harmless message Hmm...You had some extra variables I don't know about...I'll try to keep 'em. Propagating recommended variable dont_use_nlink Propagating recommended variable nmopts + Propagating recommended variable reg_infty Read the File::Find documentation for more information about dont_use_nlink +Your perl will be built with a stack size of ${stack_size}k and a regular +expression repeat count limit of $reg_infty. If you want alternative +values, see the file hints/machten.sh for advice on how to change them. + Tests io/fs test 4 and op/stat test 3 @@ -104,3 +162,5 @@ on directories. EOM expr "$osvers" \< "4.1" >/dev/null && test -r ./broken-db.msg && \ . ./broken-db.msg + +unset stack_size X diff --git a/t/op/re_tests b/t/op/re_tests index 9217fcc..6154bff 100644 --- a/t/op/re_tests +++ b/t/op/re_tests @@ -354,9 +354,9 @@ a(?:b|(c|e){1,2}?|d)+?(.) ace y $1$2 ce '(ab)\d\1'i Ab4ab y $1 Ab '(ab)\d\1'i ab4Ab y $1 ab foo\w*\d{4}baz foobar1234baz y $& foobar1234baz -a{1,32766} aaa y $& aaa -a{1,32767} - c - /a{1,32767}/: Quantifier in {,} bigger than -a{1,32768} - c - /a{1,32768}/: Quantifier in {,} bigger than +a{1,$reg_infty_m} aaa y $& aaa +a{1,$reg_infty} - c - /a{1,$reg_infty}/: Quantifier in {,} bigger than +a{1,$reg_infty_p} - c - /a{1,$reg_infty_p}/: Quantifier in {,} bigger than a(?{})b cabd y $& ab a(?{)b - c - /a(?{)b/: Sequence (?{...}) not terminated or not {}-balanced a(?{{})b - c - /a(?{{})b/: Sequence (?{...}) not terminated or not {}-balanced diff --git a/t/op/regexp.t b/t/op/regexp.t index 2736084..a4783ba 100755 --- a/t/op/regexp.t +++ b/t/op/regexp.t @@ -22,11 +22,22 @@ # interpolating that string after the match, or start of error message. # # Columns 1, 2 and 5 are \n-interpolated. +# +# The variables $reg_infty, $reg_infty_m and $reg_infty_m in columns 1 +# and 5 are replaced respectively with the configuration value reg_infty, +# reg_infty-1 and reg_infty+1, or if reg_infty is not defined in the +# configuration, default values. No other variables are substituted. + $iters = shift || 1; # Poor man performance suite, 10000 is OK. -open(TESTS,'op/re_tests') || open(TESTS,'t/op/re_tests') - || die "Can't open re_tests"; +chdir 't' if -d 't'; +@INC = "../lib"; +eval 'use Config'; # Defaults assumed if this fails +$reg_infty = defined $Config{reg_infty} ? $Config{reg_infty} : 32767; +$reg_infty_m = $reg_infty - 1; $reg_infty_p = $reg_infty + 1; + +open(TESTS,'op/re_tests') || die "Can't open re_tests"; while () { } $numtests = $.; @@ -39,6 +50,8 @@ TEST: while () { ($pat, $subject, $result, $repl, $expect) = split(/[\t\n]/,$_); $input = join(':',$pat,$subject,$result,$repl,$expect); + infty_subst(\$pat); + infty_subst(\$expect); $pat = "'$pat'" unless $pat =~ /^[:']/; $pat =~ s/\\n/\n/g; $subject =~ s/\\n/\n/g; @@ -69,3 +82,11 @@ while () { } close(TESTS); + +sub infty_subst # Special-case substitution +{ # of $reg_infty and friends + my $tp = shift; + $$tp =~ s/,\$reg_infty_m}/,$reg_infty_m}/o; + $$tp =~ s/,\$reg_infty_p}/,$reg_infty_p}/o; + $$tp =~ s/,\$reg_infty}/,$reg_infty}/o; +}