From c5a7e2cbb626d7a9087cdf7d5c067f9b4d2bd3fb Mon Sep 17 00:00:00 2001 From: jakubvrana Date: Thu, 20 Aug 2009 14:43:01 +0000 Subject: [PATCH] Fix long SQL query crash (bug #2839231) Use ungreedy regular expressions git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@985 7c3ca157-0c34-0410-bff1-cbf682f78f5c --- adminer/select.inc.php | 4 ++-- adminer/sql.inc.php | 2 +- editor/include/adminer.inc.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/adminer/select.inc.php b/adminer/select.inc.php index 82383415..13a5e380 100644 --- a/adminer/select.inc.php +++ b/adminer/select.inc.php @@ -85,10 +85,10 @@ if ($_POST && !$error) { $file = preg_replace("~^\xEF\xBB\xBF~", '', $file); //! character set $cols = ""; $rows = array(); //! packet size - preg_match_all('~("[^"]*"|[^"\\n])+~', $file, $matches); + preg_match_all('~("[^"]*"|[^"\\n])+~U', $file, $matches); foreach ($matches[0] as $key => $val) { $row = array(); - preg_match_all('~(("[^"]*")+|[^,]*),~', "$val,", $matches2); + preg_match_all('~(("[^"]*")+|[^,]*),~U', "$val,", $matches2); if (!$key && !array_diff($matches2[1], array_keys($fields))) { //! doesn't work with column names containing ",\n // first row corresponds to column names - use it for table structure $cols = " (" . implode(", ", array_map('idf_escape', $matches2[1])) . ")"; diff --git a/adminer/sql.inc.php b/adminer/sql.inc.php index 587c1122..42f51eef 100644 --- a/adminer/sql.inc.php +++ b/adminer/sql.inc.php @@ -31,7 +31,7 @@ if (!$error && $_POST) { } elseif (preg_match('(' . preg_quote($delimiter) . '|[\'`"]|/\\*|-- |#|$)', $query, $match, PREG_OFFSET_CAPTURE, $offset)) { if ($match[0][0] && $match[0][0] != $delimiter) { // is not end of a query - find closing part - $pattern = ($match[0][0] == "-- " || $match[0][0] == "#" ? '~.*~' : ($match[0][0] == "/*" ? '~.*\\*/~sU' : '~\\G([^\\\\' . $match[0][0] . ']|\\\\.)*(' . $match[0][0] . '|$)~s')); //! respect sql_mode NO_BACKSLASH_ESCAPES + $pattern = ($match[0][0] == "-- " || $match[0][0] == "#" ? '~.*~' : ($match[0][0] == "/*" ? '~.*\\*/~sU' : '~\\G([^\\\\' . $match[0][0] . ']|\\\\.)*(' . $match[0][0] . '|$)~sU')); //! respect sql_mode NO_BACKSLASH_ESCAPES preg_match($pattern, $query, $match, PREG_OFFSET_CAPTURE, $match[0][1] + 1); $offset = $match[0][1] + strlen($match[0][0]); } else { diff --git a/editor/include/adminer.inc.php b/editor/include/adminer.inc.php index a960a928..80d350d3 100644 --- a/editor/include/adminer.inc.php +++ b/editor/include/adminer.inc.php @@ -326,7 +326,7 @@ ORDER BY ORDINAL_POSITION"); //! requires MySQL 5 if ($function == "now") { return "$function()"; } - $return = $dbh->quote(ereg('date|timestamp', $field["type"]) && preg_match('(^' . preg_replace('~(\\\\\\$([0-9]))~', '(?P[0-9]+)', preg_quote(lang('$1-$3-$5'))) . '(.*))', $value, $match) + $return = $dbh->quote(ereg('date|timestamp', $field["type"]) && preg_match('(^' . preg_replace('~(\\\\\\$([0-9]))~', '(?P[0-9]+)', preg_quote(lang('$1-$3-$5'))) . '(.*))', $value, $match) //! {1,2} instead of + except year ? ($match["p1"] ? $match["p1"] : ($match["p2"] < 70 ? 20 : 19) . $match["p2"]) . "-$match[p3]$match[p4]-$match[p5]$match[p6]" . end($match) : $value );