This repository has been archived by the owner on May 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 728
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add variant regexp assemble script to handle possessive qualifiers This is an interim solution and these changes will eventually be added back to regexp-assemble.pl * Use possessive qualifiers to tight this up and solve ReDoS problem Should address the remaining problem with #1359.
- Loading branch information
Showing
3 changed files
with
33 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env perl | ||
# | ||
# Create one regexp from a set of regexps. | ||
# Regexps can be submitted via standard input, one per line. | ||
# | ||
# Requires Regexp::Assemble Perl module. | ||
# To install: cpan install Regexp::Assemble | ||
# | ||
# See: http://blog.modsecurity.org/2007/06/optimizing-regu.html | ||
# | ||
|
||
use strict; | ||
use Regexp::Assemble; | ||
|
||
my $ra = Regexp::Assemble->new; | ||
while (<>) | ||
{ | ||
# Handle possessive qualifiers | ||
# https://rt.cpan.org/Public/Bug/Display.html?id=50228#txn-672717 | ||
my $arr = $ra->lexstr($_); | ||
for (my $n = 0; $n < $#$arr - 1; ++$n) | ||
{ | ||
if ($arr->[$n] =~ /\+$/ and $arr->[$n + 1] eq '+') { | ||
$arr->[$n] .= splice(@$arr, $n + 1, 1); | ||
} | ||
} | ||
$ra->insert(@$arr); | ||
} | ||
print $ra->as_string() . "\n"; |