diff mbox

[v2] sanitize paths used in regular expression

Message ID 1452883231-15682-1-git-send-email-zwelch@codesourcery.com
State New
Headers show

Commit Message

Zachary T Welch Jan. 15, 2016, 6:40 p.m. UTC
Does this version look better?  I am not sure if this the right place
to put the new helper, so let me know if there is a better spot for it.

	gcc/testsuite/lib/
	* prune.exp (prune_file_path): Sanitize path used in regex.
	(escape_regex_chars): New.

Signed-off-by: Zachary T Welch <zwelch@codesourcery.com>
---
 gcc/testsuite/lib/prune.exp | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

Comments

Mike Stump Jan. 15, 2016, 6:48 p.m. UTC | #1
On Jan 15, 2016, at 10:40 AM, Zachary T Welch <zwelch@codesourcery.com> wrote:
> Does this version look better?

Ok.

> I am not sure if this the right place to put the new helper, so let me know if there is a better spot for it.

So, someone that wants to rehome the helper is free to do that.
Zachary T Welch Jan. 18, 2016, 10:45 p.m. UTC | #2
On 01/15/2016 10:48 AM, Mike Stump wrote:
> On Jan 15, 2016, at 10:40 AM, Zachary T Welch <zwelch@codesourcery.com> wrote:
>> Does this version look better?
> 
> Ok.
> 
>> I am not sure if this the right place to put the new helper, so let me know if there is a better spot for it.
> 
> So, someone that wants to rehome the helper is free to do that.

Excellent.  I do not have write access to the repository, so can this
get committed?

Thanks,
Zachary T Welch Feb. 8, 2016, 10:26 p.m. UTC | #3
On 01/18/2016 02:45 PM, Zach Welch wrote:
> On 01/15/2016 10:48 AM, Mike Stump wrote:
>> On Jan 15, 2016, at 10:40 AM, Zachary T Welch <zwelch@codesourcery.com> wrote:
>>> Does this version look better?
>>
>> Ok.
>>
>>> I am not sure if this the right place to put the new helper, so let me know if there is a better spot for it.
>>
>> So, someone that wants to rehome the helper is free to do that.
> 
> Excellent.  I do not have write access to the repository, so can this
> get committed?

Ping.  From what I see, my patch has not yet been committed.  Can I talk
someone into taking care of that for me?

FWIW, I developed it for 5.2, but I am happy seeing it go in on any
branch that makes sense.

Thanks,
Mike Stump March 29, 2016, 9:59 p.m. UTC | #4
On Feb 8, 2016, at 2:26 PM, Zach Welch <zwelch@codesourcery.com> wrote:
> 
> Ping.  From what I see, my patch has not yet been committed.  Can I talk
> someone into taking care of that for me?

I had hoped that someone would commit it for you.

Committed revision 234533.
diff mbox

Patch

diff --git a/gcc/testsuite/lib/prune.exp b/gcc/testsuite/lib/prune.exp
index 8e4c203..fd3c4ea 100644
--- a/gcc/testsuite/lib/prune.exp
+++ b/gcc/testsuite/lib/prune.exp
@@ -73,12 +73,33 @@  proc prune_gcc_output { text } {
     return $text
 }
 
+# escape metacharacters in literal string, so it can be used in regex
+
+proc escape_regex_chars { line } {
+    return [string map {"^" "\\^"
+			"$" "\\$"
+			"(" "\\("
+			")" "\\)"
+			"[" "\\["
+			"]" "\\]"
+			"{" "\\{"
+			"}" "\\}"
+			"." "\\."
+			"\\" "\\\\"
+			"?" "\\?"
+			"+" "\\+"
+			"*" "\\*"
+			"|" "\\|"} $line]
+}
+
 proc prune_file_path { text } {
     global srcdir
 
+    set safedir [escape_regex_chars $srcdir]
+    regsub -all "$safedir\/"  $text "" text
+
     # Truncate absolute file path into relative path.
-    set topdir "[file dirname [file dirname [file dirname $srcdir]]]"
-    regsub -all "$srcdir\/" $text "" text
+    set topdir "[file dirname [file dirname [file dirname $safedir]]]"
     regsub -all "$topdir\/" $text "" text
 
     return $text