[BUGFIX] Check for query failures in admin methods 84/25484/2
authorThomas Maroschik <tmaroschik@dfau.de>
Mon, 21 Oct 2013 17:18:23 +0000 (19:18 +0200)
committerFrancois Suter <francois@typo3.org>
Mon, 18 Nov 2013 11:23:13 +0000 (12:23 +0100)
In the DatabaseConnection class the two methods admin_get_fields
and admin_get_keys throw a fatal error when a query failure occurs.

This fix introduces two checks that prevent the methods from fataling
and return an empty result on failure.

Fixes: #53014
Releases: 6.0, 6.1, 6.2

Change-Id: I40f7e52fe14b7d75766f0484e42834b0e1b1a5dc
Reviewed-on: https://review.typo3.org/24940
Reviewed-by: Jigal van Hemert
Tested-by: Jigal van Hemert
Reviewed-on: https://review.typo3.org/25484
Reviewed-by: Francois Suter
Tested-by: Francois Suter
typo3/sysext/core/Classes/Database/DatabaseConnection.php

index 108cb00..23743bf 100644 (file)
@@ -1352,10 +1352,12 @@ class DatabaseConnection {
                }
                $output = array();
                $columns_res = $this->link->query('SHOW COLUMNS FROM `' . $tableName . '`');
-               while ($fieldRow = $columns_res->fetch_assoc()) {
-                       $output[$fieldRow['Field']] = $fieldRow;
+               if ($columns_res !== FALSE) {
+                       while ($fieldRow = $columns_res->fetch_assoc()) {
+                               $output[$fieldRow['Field']] = $fieldRow;
+                       }
+                       $columns_res->free();
                }
-               $columns_res->free();
                return $output;
        }
 
@@ -1372,10 +1374,12 @@ class DatabaseConnection {
                }
                $output = array();
                $keyRes = $this->link->query('SHOW KEYS FROM `' . $tableName . '`');
-               while ($keyRow = $keyRes->fetch_assoc()) {
-                       $output[] = $keyRow;
+               if ($keyRes !== FALSE) {
+                       while ($keyRow = $keyRes->fetch_assoc()) {
+                               $output[] = $keyRow;
+                       }
+                       $keyRes->free();
                }
-               $keyRes->free();
                return $output;
        }