From 08cc05bbe8340a27c5a1a8c8a7c0ef122c045283 Mon Sep 17 00:00:00 2001 From: "peter.wiseman" Date: Mon, 13 Aug 2012 21:16:19 +1000 Subject: [PATCH] [#28912] Simplified regex to prevent stack overflow on long strings --- libraries/joomla/language/language.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libraries/joomla/language/language.php b/libraries/joomla/language/language.php index 0eadf6dbeb..2a501d3f0b 100644 --- a/libraries/joomla/language/language.php +++ b/libraries/joomla/language/language.php @@ -824,7 +824,7 @@ protected function parse($filename) // Initialise variables for manually parsing the file for common errors. $blacklist = array('YES', 'NO', 'NULL', 'FALSE', 'ON', 'OFF', 'NONE', 'TRUE'); - $regex = '/^(|(\[[^\]]*\])|([A-Z][A-Z0-9_\-\.]*\s*=(\s*(("([^"]|\\\")*")|(_QQ_)))+))\s*(;.*)?$/'; + $regex = '/^(|(\[[^\]]*\])|([A-Z][A-Z0-9_\-\.]*\s*=(\s*(("[^"]*")|(_QQ_)))+))\s*(;.*)?$/'; $this->debug = false; $errors = array(); @@ -842,6 +842,9 @@ protected function parse($filename) // Check that the key is not in the blacklist and that the line format passes the regex. $key = strtoupper(trim(substr($line, 0, strpos($line, '=')))); + // Workaround to reduce regex complexity when matching escaped quotes + $line = str_replace('\"', '_QQ_', $line); + if (!preg_match($regex, $line) || in_array($key, $blacklist)) { $errors[] = $lineNumber;