]> git.joonet.de Git - adminer.git/commitdiff
Protection against big POST data
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Tue, 18 Mar 2008 10:29:20 +0000 (10:29 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Tue, 18 Mar 2008 10:29:20 +0000 (10:29 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@373 7c3ca157-0c34-0410-bff1-cbf682f78f5c

17 files changed:
abstraction.inc.php
call.inc.php
create.inc.php
database.inc.php
edit.inc.php
editing.inc.php
foreign.inc.php
functions.inc.php
index.php
indexes.inc.php
lang/cs.inc.php
procedure.inc.php
processlist.inc.php
select.inc.php
sql.inc.php
trigger.inc.php
user.inc.php

index aa56905e7aacc27f1f3c7704e34bfe239a47cffb..36ac73856759f35bcf380ad0e3f134b37422d25c 100644 (file)
@@ -195,7 +195,7 @@ if (extension_loaded("mysqli")) {
 
 } else {
        page_header(lang('No MySQL extension'), null);
-       echo "<p class='error'>" . lang('None of supported PHP extensions (%s) are available.', 'mysqli, mysql, pdo') . "</p>\n";
+       echo "<p class='error'>" . lang('None of supported PHP extensions (%s) are available.', 'MySQLi, MySQL, PDO') . "</p>\n";
        page_footer("auth");
        exit;
 }
index b805e5bc426688d1d497167f23c97ece30e8d0ca..d56489e30e8789d6ee32e86920fe6f34112529db 100644 (file)
@@ -13,7 +13,9 @@ foreach ($routine["fields"] as $i => $field) {
        }
 }
 
-if ($_POST) {
+if ($error) {
+       echo "<p class='error'>" . htmlspecialchars($error) . "</p>\n";
+} elseif ($_POST) {
        $call = array();
        foreach ($routine["fields"] as $key => $field) {
                if (in_array($key, $in)) {
index ebb430ce63819933f4d466d29ab808ecc818c209..440c37eb7af0ba7953369fe2ad433143fa2cbc4c 100644 (file)
@@ -65,14 +65,15 @@ while ($row = $result->fetch_assoc()) {
 }
 $result->free();
 
+if ($error) {
+       echo "<p class='error'>" . lang('Unable to operate table') . ": " . htmlspecialchars($error) . "</p>\n";
+}
 if ($_POST) {
        $row = $_POST;
        ksort($row["fields"]);
        $row["fields"] = array_values($row["fields"]);
        if ($_POST["add"]) {
                array_splice($row["fields"], key($_POST["add"]), 0, array(array()));
-       } elseif (!$_POST["drop_col"]) {
-               echo "<p class='error'>" . lang('Unable to operate table') . ": " . htmlspecialchars($error) . "</p>\n";
        }
        if ($row["auto_increment_col"]) {
                $row["fields"][$row["auto_increment_col"] - 1]["auto_increment"] = true;
index b7243fefa0af4231d77250c005c5233a3d60d471..353f7d7353853f487b1700eab8e941f826a9c058 100644 (file)
@@ -28,12 +28,13 @@ if ($_POST && !$error) {
        }
        $error = $mysql->error;
 }
-
 page_header(strlen($_GET["db"]) ? lang('Alter database') : lang('Create database'), array(), $_GET["db"]);
-$collations = collations();
 
-if ($_POST) {
+$collations = collations();
+if ($error) {
        echo "<p class='error'>" . lang('Unable to operate database') . ": " . htmlspecialchars($error) . "</p>\n";
+}
+if ($_POST) {
        $name = $_POST["name"];
        $collate = $_POST["collation"];
 } else {
index 2bace030d48a00071d395993b3c816dbdaccf72a..c673a26e779508e1ba4003840805a4fb16457324 100644 (file)
@@ -43,8 +43,10 @@ if ($_POST && !$error) {
 }
 page_header((isset($_GET["default"]) ? lang('Default values') : ($_GET["where"] ? lang('Edit') : lang('Insert'))), array((isset($_GET["default"]) ? "table" : "select") => $_GET["edit"]), $_GET["edit"]);
 
-if ($_POST) {
+if ($error) {
        echo "<p class='error'>" . lang('Error during saving') . ": " . htmlspecialchars($error) . "</p>\n";
+}
+if ($_POST) {
        $row = (array) $_POST["fields"];
        foreach ((array) $_POST["null"] as $key => $val) {
                $row[$key] = null;
index 7b2c4c98c62ce1b8821a7c25fd91b127f9795f91..6649205550e4b1f9989e9035a67c98d880be8c83 100644 (file)
@@ -51,8 +51,8 @@ function process_input($name, $field) {
                return (isset($_GET["default"]) ? "'" . implode(",", array_map(array($mysql, 'escape_string'), (array) $value)) . "'" : array_sum((array) $value));
        } elseif (preg_match('~binary|blob~', $field["type"])) {
                $file = get_file($name);
-               if (!is_string($file) && !$field["null"]) {
-                       return false; //! report errors, also empty $_POST (too big POST data, not only FILES)
+               if (!is_string($file) && ($file != UPLOAD_ERR_NO_FILE || !$field["null"])) {
+                       return false; //! report errors
                }
                return "_binary'" . (is_string($file) ? $mysql->escape_string($file) : "") . "'";
        } elseif ($field["type"] == "timestamp" && $value == "CURRENT_TIMESTAMP") {
index ceb4b01b209d718035a74e536e5cada2798e09d1..03ee107244aabd4e6676a016c748a0c70bd1acad 100644 (file)
@@ -24,7 +24,6 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["change"] && !$_POST["change-
        }
        $error = $mysql->error;
 }
-
 page_header(lang('Foreign key'), array("table" => $_GET["foreign"]), $_GET["foreign"]);
 
 $tables = array();
@@ -36,6 +35,9 @@ while ($row = $result->fetch_assoc()) {
 }
 $result->free();
 
+if ($error) {
+       echo "<p class='error'>" . lang('Unable to operate foreign keys') . ": " . htmlspecialchars($error) . "</p>\n";
+}
 if ($_POST) {
        $row = $_POST;
        ksort($row["source"]);
@@ -43,8 +45,6 @@ if ($_POST) {
                $row["source"][] = "";
        } elseif ($_POST["change"] || $_POST["change-js"]) {
                $row["target"] = array();
-       } else {
-               echo "<p class='error'>" . lang('Unable to operate foreign keys') . ": " . htmlspecialchars($error) . "</p>\n";
        }
 } elseif (strlen($_GET["name"])) {
        $foreign_keys = foreign_keys($_GET["foreign"]);
index 6a5291a94c67414f29b860527bfd4d3446fc1cc8..12c869c7b148b695919966fc84e5263c4aac8303 100644 (file)
@@ -204,7 +204,7 @@ function remove_from_uri($param = "") {
 function get_file($key) {
        if (isset($_POST["files"][$key])) {
                $length = strlen($_POST["files"][$key]);
-               return ($length & $length < 4 ? intval($_POST["files"][$key]) : base64_decode($_POST["files"][$key]));
+               return ($length && $length < 4 ? intval($_POST["files"][$key]) : base64_decode($_POST["files"][$key]));
        }
        return (!$_FILES[$key] || $_FILES[$key]["error"] ? $_FILES[$key]["error"] : file_get_contents($_FILES[$key]["tmp_name"]));
 }
index 27859d9b9fcf47418920b9a37ce138883cc63757..4b747c540dddc449b850da3e3353fe86e0e4e489 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1,5 +1,5 @@
 <?php
-/** phpMinAdmin - MySQL management tool
+/** phpMinAdmin - Compact MySQL management
 * @link http://phpminadmin.sourceforge.net
 * @author Jakub Vrana, http://php.vrana.cz
 * @copyright 2007 Jakub Vrana
@@ -50,8 +50,13 @@ if (isset($_GET["dump"])) {
                include "./privileges.inc.php";
        } else { // uses CSRF token
                include "./editing.inc.php";
+               $error = "";
                if ($_POST) {
-                       $error = (in_array($_POST["token"], (array) $TOKENS) ? "" : lang('Invalid CSRF token. Send the form again.'));
+                       if (!in_array($_POST["token"], (array) $TOKENS)) {
+                               $error = lang('Invalid CSRF token. Send the form again.');
+                       }
+               } elseif ($_SERVER["REQUEST_METHOD"] == "POST") {
+                       $error = lang('Too big POST data. Reduce the data or increase the "post_max_size" configuration directive.');
                }
                $token = ($_POST && !$error ? $_POST["token"] : token());
                if (isset($_GET["default"])) {
@@ -90,7 +95,6 @@ if (isset($_GET["dump"])) {
                } elseif (isset($_GET["select"])) {
                        include "./select.inc.php";
                } else {
-                       $TOKENS = array();
                        page_header(lang('Database') . ": " . htmlspecialchars($_GET["db"]), false);
                        echo '<p><a href="' . htmlspecialchars($SELF) . 'database=">' . lang('Alter database') . "</a></p>\n";
                        echo '<p><a href="' . htmlspecialchars($SELF) . 'schema=">' . lang('Database schema') . "</a></p>\n";
index e1acd43e302203cca77abf2ecc224849a84f9f96..4e8ccaf54ce8f486890565b5d0259e1570ef0012 100644 (file)
@@ -40,12 +40,13 @@ if ($_POST && !$error && !$_POST["add"]) {
 }
 page_header(lang('Indexes'), array("table" => $_GET["indexes"]), $_GET["indexes"]);
 
+if ($error) {
+       echo "<p class='error'>" . lang('Unable to operate indexes') . ": " . htmlspecialchars($error) . "</p>\n";
+}
 $fields = array_keys(fields($_GET["indexes"]));
 if ($_POST) {
        $row = $_POST;
-       if (!$_POST["add"]) {
-               echo "<p class='error'>" . lang('Unable to operate indexes') . ": " . htmlspecialchars($error) . "</p>\n";
-       } else {
+       if ($_POST["add"]) {
                foreach ($row["indexes"] as $key => $index) {
                        if (strlen($index["columns"][count($index["columns"])])) {
                                $row["indexes"][$key]["columns"][] = "";
index ad82bae828ec830b6d8456496bf2084c99457d26..7fa3723e595957c1fc51c2dfca35d3ee9170e494 100644 (file)
@@ -167,4 +167,5 @@ $translations = array(
        'all' => 'vše',
        'Delete selected' => 'Smazat označené',
        'Truncate table' => 'Promazat tabulku',
+       'Too big POST data. Reduce the data or increase the "post_max_size" configuration directive.' => 'Příliš velká POST data. Zmenšete data nebo zvyšte hodnotu konfigurační direktivy "post_max_size".',
 );
index f80384e4c835a6cbb52f96ef5d313eb60867ee48..e9629ce08b17bbf0d24b1af7f483c6121cc42df7 100644 (file)
@@ -29,12 +29,14 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"]) {
        }
        $error = $mysql->error;
 }
-
 page_header(strlen($_GET["procedure"])
 ? (isset($_GET["function"]) ? lang('Alter function') : lang('Alter procedure')) . ": " . htmlspecialchars($_GET["procedure"])
 : (isset($_GET["function"]) ? lang('Create function') : lang('Create procedure'))
 );
 
+if ($error) {
+       echo "<p class='error'>" . lang('Unable to operate routine') . ": " . htmlspecialchars($error) . "</p>\n";
+}
 $collations = get_vals("SHOW CHARACTER SET");
 if ($_POST) {
        $row = $_POST;
@@ -43,8 +45,6 @@ if ($_POST) {
        $row["fields"] = array_values($row["fields"]);
        if ($_POST["add"]) {
                array_splice($row["fields"], key($_POST["add"]), 0, array(array()));
-       } elseif (!$_POST["drop_col"]) {
-               echo "<p class='error'>" . lang('Unable to operate routine') . ": " . htmlspecialchars($error) . "</p>\n";
        }
 } elseif (strlen($_GET["procedure"])) {
        $row = routine($_GET["procedure"], $routine);
index f8dfc170f374f125eda277494194ac65fd85ffbe..1cd3dabdfaf53245e7e84a769b51e3e732dd1981 100644 (file)
@@ -11,10 +11,9 @@ if ($_POST && !$error) {
        }
        $error = $mysql->error;
 }
-
 page_header(lang('Process list'));
 
-if ($_POST) {
+if ($error) {
        echo "<p class='error'>" . lang('Unable to kill process') . ": " . htmlspecialchars($error) . "</p>\n";
 }
 ?>
index 27671835c95dc833b9540356db9d38264c67c4a9..1476606cf64dfeb87b163d7a4867879fa5b365cf 100644 (file)
@@ -83,9 +83,9 @@ if ($_POST && !$error) {
        }
        $error = $mysql->error;
 }
-
 page_header(lang('Select') . ": " . htmlspecialchars($_GET["select"]));
-if ($_POST) {
+
+if ($error) {
        echo "<p class='error'>" . lang('Error during deleting') . ": " . htmlspecialchars($error) . "</p>\n";
 }
 
index b6088ae47992ff7e12e19832b51b9363990cd527..d461584c956e99209101a17f77dff0be17dc3e02 100644 (file)
@@ -3,11 +3,10 @@ if (isset($_POST["query"])) {
        setcookie("highlight", $_POST["highlight"], strtotime("+1 month"), preg_replace('~\\?.*~', '', $_SERVER["REQUEST_URI"]));
        $_COOKIE["highlight"] = $_POST["highlight"];
 }
-
 page_header(lang('SQL command'));
 
-if ($_POST && $error) {
-       echo "<p class='error'>$error</p>\n";
+if ($error) {
+       echo "<p class='error'>" . htmlspecialchars($error) . "</p>\n";
 } elseif ($_POST && is_string($query = (isset($_POST["query"]) ? $_POST["query"] : get_file("sql_file")))) {
        $delimiter = ";";
        $offset = 0;
index b74b396220236fc55124b2e3aef9cacdc74b65c3..4a72bd5c6a1a630ebc6b0901ab16248ba8ccac06 100644 (file)
@@ -19,12 +19,13 @@ if ($_POST && !$error) {
        }
        $error = $mysql->error;
 }
-
 page_header(strlen($_GET["name"]) ? lang('Alter trigger') . ": " . htmlspecialchars($_GET["name"]) : lang('Create trigger'), array("table" => $_GET["trigger"]));
 
+if ($error) {
+       echo "<p class='error'>" . lang('Unable to operate trigger') . ": " . htmlspecialchars($error) . "</p>\n";
+}
 if ($_POST) {
        $row = $_POST;
-       echo "<p class='error'>" . lang('Unable to operate trigger') . ": " . htmlspecialchars($error) . "</p>\n";
 } elseif (strlen($_GET["name"])) {
        $result = $mysql->query("SHOW TRIGGERS LIKE '" . $mysql->escape_string(addcslashes($_GET["trigger"], "%_")) . "'");
        while ($row = $result->fetch_assoc()) {
index 6bd8c7840f3e92b7451d9780d75f0d3ec78253b2..e74d1e709a192f0d21869c06ccd5de2534f1a980 100644 (file)
@@ -117,13 +117,14 @@ if ($_POST && !$error) {
                $error = $mysql->error;
        }
 }
-
 page_header((isset($_GET["host"]) ? lang('Username') . ": " . htmlspecialchars("$_GET[user]@$_GET[host]") : lang('Create user')), array("privileges" => lang('Privileges')));
 
+if ($error) {
+       echo "<p class='error'>" . lang('Unable to operate user') . ": " . htmlspecialchars($error) . "</p>\n";
+}
 if ($_POST) {
        $row = $_POST;
        $grants = $new_grants;
-       echo "<p class='error'>" . lang('Unable to operate user') . ": " . htmlspecialchars($error) . "</p>\n";
 } else {
        $row = $_GET + array("host" => "localhost");
        $row["pass"] = $old_pass;