Subject: | Optimize some regexes |
The attached patch optimizes some regexes in Mail::Address. Without the * after the [], Perl's C stack overflowed when parsing an extremely long quoted-string.
diff -ur MailTools-1.67/blib/lib/Mail/Address.pm MailTools-1.67-fix/blib/lib/Mail/Address.pm
--- MailTools-1.67/blib/lib/Mail/Address.pm 2005-01-20 01:17:54.000000000 -0800
+++ MailTools-1.67-fix/blib/lib/Mail/Address.pm 2005-11-22 11:26:25.000000000 -0800
@@ -119,8 +119,8 @@
next;
}
- s/^("([^"\\]|\\.)*")\s*// # "..."
- || s/^(\[([^\]\\]|\\.)*\])\s*// # [...]
+ s/^("(?:[^"\\]*|\\.)*")\s*// # "..."
+ || s/^(\[(?:[^\]\\]*|\\.)*\])\s*// # [...]
|| s/^([^\s\Q()<>\@,;:\\".[]\E]+)\s*//
|| s/^([\Q()<>\@,;:\\".[]\E])\s*//
and do { push(@words, $1); next; };
diff -ur MailTools-1.67/Mail/Address.pm MailTools-1.67-fix/Mail/Address.pm
--- MailTools-1.67/Mail/Address.pm 2005-01-20 01:17:54.000000000 -0800
+++ MailTools-1.67-fix/Mail/Address.pm 2005-11-22 11:26:25.000000000 -0800
@@ -119,8 +119,8 @@
next;
}
- s/^("([^"\\]|\\.)*")\s*// # "..."
- || s/^(\[([^\]\\]|\\.)*\])\s*// # [...]
+ s/^("(?:[^"\\]*|\\.)*")\s*// # "..."
+ || s/^(\[(?:[^\]\\]*|\\.)*\])\s*// # [...]
|| s/^([^\s\Q()<>\@,;:\\".[]\E]+)\s*//
|| s/^([\Q()<>\@,;:\\".[]\E])\s*//
and do { push(@words, $1); next; };
Only in MailTools-1.67-fix/Mail: Address.pm~