This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH: Correct use of regsub in lib/compat.exp
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 15 May 2005 16:03:52 -0700
- Subject: PATCH: Correct use of regsub in lib/compat.exp
- Reply-to: mark at codesourcery dot com
We had this code in lib/compat.exp:
! regsub "^$srcdir/?" $src1 "" testcase
! regsub "^$tmpdir/?" $testcase "tmpdir-" testcase
This is unsafe, because "$srcdir" or "$tmpdir" might themselves
contain regular-expression characters. That situation leads to weird
messages, like:
couldn't compile regular expression pattern: quantifier operand
Fixed as follows, applied to the 3.4, 4.0, and mainline branches as
near-obvious, and tested on x86_64-unknown-linux-gnu.
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
2005-05-15 Mark Mitchell <mark@codesourcery.com>
* lib/compat.exp (compat-execute): Do not use regsub unsafely.
Index: lib/compat.exp
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/lib/compat.exp,v
retrieving revision 1.12
diff -c -5 -p -r1.12 compat.exp
*** lib/compat.exp 30 Nov 2004 21:37:14 -0000 1.12
--- lib/compat.exp 15 May 2005 22:54:25 -0000
*************** proc compat-execute { src1 sid use_alt }
*** 277,288 ****
regsub "sid" "sid_x_alt.o" $sid obj2_alt
regsub "sid" "sid_y_tst.o" $sid obj3_tst
regsub "sid" "sid_y_alt.o" $sid obj3_alt
# Get the base name of this test, for use in messages.
! regsub "^$srcdir/?" $src1 "" testcase
! regsub "^$tmpdir/?" $testcase "tmpdir-" testcase
regsub "_main.*" $testcase "" testcase
# Set up the base name of executable files so they'll be unique.
regsub -all "\[./\]" $testcase "-" execbase
# If we couldn't rip $srcdir out of `src1' then just do the best we can.
--- 277,298 ----
regsub "sid" "sid_x_alt.o" $sid obj2_alt
regsub "sid" "sid_y_tst.o" $sid obj3_tst
regsub "sid" "sid_y_alt.o" $sid obj3_alt
# Get the base name of this test, for use in messages.
! set testcase "$src1"
! # Remove the $srcdir and $tmpdir prefixes from $src1. (It would
! # be possible to use "regsub" here, if we were careful to escape
! # all regular expression characters in $srcdir and $tmpdir, but
! # that would be more complicated that this approach.)
! if {[string first "$srcdir/" "$src1"] == 0} {
! set testcase [string range "$src1" [string length "$srcdir/"] end]
! }
! if {[string first "$tmpdir/" "$testcase"] == 0} {
! set testcase [string range "$testcase" [string length "$tmpdir/"] end]
! set testcase "tmpdir-$testcase"
! }
regsub "_main.*" $testcase "" testcase
# Set up the base name of executable files so they'll be unique.
regsub -all "\[./\]" $testcase "-" execbase
# If we couldn't rip $srcdir out of `src1' then just do the best we can.