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
This commit is contained in:
jakubvrana 2009-08-20 14:43:01 +00:00
parent c709576c0e
commit c5a7e2cbb6
3 changed files with 4 additions and 4 deletions

View file

@ -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])) . ")";

View file

@ -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 {

View file

@ -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<p\\2>[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<p\\2>[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
);