From e2d2946a06c558710a185b16f6212fb8f2aa6c09 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Thu, 4 Oct 2007 17:29:15 +0000 Subject: [PATCH] bug #1798786 [import] Wrong error message when a string contains semicolon --- ChangeLog | 1 + libraries/import/sql.php | 40 ++++++++++++++++++++++++---------------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9ece09dfb..d1b1b5c58 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,7 @@ $HeadURL: https://phpmyadmin.svn.sourceforge.net/svnroot/phpmyadmin/trunk/phpMyA - bug #1764195 [views] DROP button does not work on defective views - bug #1805773 [relations] browse foreign values: return values not escaped, thanks to Alex Rambau +- bug #1798786 [import] Wrong error message when a string contains semicolon 2.11.1.0 (2007-09-20) diff --git a/libraries/import/sql.php b/libraries/import/sql.php index 53d12454f..602df0b1e 100644 --- a/libraries/import/sql.php +++ b/libraries/import/sql.php @@ -73,43 +73,51 @@ while (!($finished && $i >= $len) && !$error && !$timeout_passed) { //while (($i < $len) && (strpos('\'";#-/', $buffer[$i]) === FALSE)) $i++; //if ($i == $len) break; $oi = $i; - $p1 = strpos($buffer, '\'', $i); - if ($p1 === FALSE) { - $p1 = 2147483647; + $big_value = 2147483647; + $first_quote = strpos($buffer, '\'', $i); + if ($first_quote === FALSE) { + $first_quote = $big_value; + } else { + $next_quote = strpos($buffer, '\'', $first_quote + 1); } $p2 = strpos($buffer, '"', $i); if ($p2 === FALSE) { - $p2 = 2147483647; + $p2 = $big_value; } - $p3 = strpos($buffer, $sql_delimiter, $i); - if ($p3 === FALSE) { - $p3 = 2147483647; - } else { + /** + * @todo it's a shortcoming to look for a delimiter that might be + * inside quotes (or even double-quotes) + * for the moment, catch the case of delimiter between quotes + */ + $first_sql_delimiter = strpos($buffer, $sql_delimiter, $i); + if ($first_sql_delimiter === FALSE) { + $first_sql_delimiter = $big_value; + } elseif ($first_sql_delimiter < $first_quote && $first_sql_delimiter > $next_quote) { $found_delimiter = true; } $p4 = strpos($buffer, '#', $i); if ($p4 === FALSE) { - $p4 = 2147483647; + $p4 = $big_value; } $p5 = strpos($buffer, '--', $i); if ($p5 === FALSE || $p5 >= ($len - 2) || $buffer[$p5 + 2] > ' ') { - $p5 = 2147483647; + $p5 = $big_value; } $p6 = strpos($buffer, '/*', $i); if ($p6 === FALSE) { - $p6 = 2147483647; + $p6 = $big_value; } $p7 = strpos($buffer, '`', $i); if ($p7 === FALSE) { - $p7 = 2147483647; + $p7 = $big_value; } $p8 = strpos($buffer, 'DELIMITER', $i); if ($p8 === FALSE || $p8 >= ($len - 11) || $buffer[$p8 + 9] > ' ') { - $p8 = 2147483647; + $p8 = $big_value; } - $i = min ($p1, $p2, $p3, $p4, $p5, $p6, $p7, $p8); - unset($p1, $p2, $p3, $p4, $p5, $p6, $p7, $p8); - if ($i == 2147483647) { + $i = min ($first_quote, $p2, $first_sql_delimiter, $p4, $p5, $p6, $p7, $p8); + unset($first_quote, $p2, $first_sql_delimiter, $p4, $p5, $p6, $p7, $p8); + if ($i == $big_value) { $i = $oi; if (!$finished) { break;