1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-17 03:53:59 +02:00

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 {