From adfa88acb5927f93444b357b7e9f7f9d617ae0ad Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Thu, 15 Aug 2024 16:52:03 +0200 Subject: [PATCH 1/2] Fix privileges assignment Signed-off-by: Kamil Tekiela --- src/Server/Privileges.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Server/Privileges.php b/src/Server/Privileges.php index 00696525bd..88b2046f19 100644 --- a/src/Server/Privileges.php +++ b/src/Server/Privileges.php @@ -219,7 +219,7 @@ class Privileges foreach ($grants as $currentGrant) { if ( ($row === null || ! isset($row[$currentGrant[0]])) - && ($row !== null || ! isset($GLOBALS[$currentGrant[0]])) + && ($row !== null || ! isset($_POST[$currentGrant[0]])) ) { continue; } @@ -227,10 +227,10 @@ class Privileges if ( ($row !== null && $row[$currentGrant[0]] === 'Y') || ($row === null - && ($GLOBALS[$currentGrant[0]] === 'Y' - || (is_array($GLOBALS[$currentGrant[0]]) - && count($GLOBALS[$currentGrant[0]]) == $_REQUEST['column_count'] - && empty($GLOBALS[$currentGrant[0] . '_none'])))) + && ($_POST[$currentGrant[0]] === 'Y' + || (is_array($_POST[$currentGrant[0]]) + && count($_POST[$currentGrant[0]]) == $_REQUEST['column_count'] + && empty($_POST[$currentGrant[0] . '_none'])))) ) { if ($enableHTML) { $privs[] = '' @@ -239,14 +239,14 @@ class Privileges $privs[] = $currentGrant[1]; } } elseif ( - ! empty($GLOBALS[$currentGrant[0]]) - && is_array($GLOBALS[$currentGrant[0]]) - && empty($GLOBALS[$currentGrant[0] . '_none']) + ! empty($_POST[$currentGrant[0]]) + && is_array($_POST[$currentGrant[0]]) + && empty($_POST[$currentGrant[0] . '_none']) ) { // Required for proper escaping of ` (backtick) in a column name $grantCols = array_map( Util::backquote(...), - $GLOBALS[$currentGrant[0]], + $_POST[$currentGrant[0]], ); if ($enableHTML) { From ae0157293b2d80e955daaec303c21dab9271d750 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Thu, 15 Aug 2024 17:10:19 +0200 Subject: [PATCH 2/2] Small refactoring Signed-off-by: Kamil Tekiela --- phpstan-baseline.neon | 4 ++-- psalm-baseline.xml | 11 ++++++----- src/Server/Privileges.php | 23 +++++++++++------------ 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index f38f0807b3..76fb761e36 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -12062,7 +12062,7 @@ parameters: - message: "#^Cannot access offset string on mixed\\.$#" - count: 2 + count: 1 path: src/Server/Privileges.php - @@ -12077,7 +12077,7 @@ parameters: - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" - count: 15 + count: 14 path: src/Server/Privileges.php - diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 2ebaedd370..da9e31913e 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -10323,6 +10323,7 @@ + @@ -10360,8 +10361,6 @@ - - @@ -10380,6 +10379,9 @@ + + + @@ -10460,9 +10462,8 @@ - - - + + diff --git a/src/Server/Privileges.php b/src/Server/Privileges.php index 88b2046f19..2fc9ad1a2d 100644 --- a/src/Server/Privileges.php +++ b/src/Server/Privileges.php @@ -217,20 +217,20 @@ class Privileges $privs = []; $allPrivileges = true; foreach ($grants as $currentGrant) { - if ( - ($row === null || ! isset($row[$currentGrant[0]])) - && ($row !== null || ! isset($_POST[$currentGrant[0]])) - ) { + if ($row !== null && isset($row[$currentGrant[0]])) { + $grantValue = $row[$currentGrant[0]]; + } elseif ($row === null && isset($_POST[$currentGrant[0]])) { + $grantValue = $_POST[$currentGrant[0]]; + } else { continue; } if ( - ($row !== null && $row[$currentGrant[0]] === 'Y') + ($grantValue === 'Y') || ($row === null - && ($_POST[$currentGrant[0]] === 'Y' - || (is_array($_POST[$currentGrant[0]]) - && count($_POST[$currentGrant[0]]) == $_REQUEST['column_count'] - && empty($_POST[$currentGrant[0] . '_none'])))) + && is_array($grantValue) + && count($grantValue) == $_REQUEST['column_count'] + && empty($_POST[$currentGrant[0] . '_none'])) ) { if ($enableHTML) { $privs[] = '' @@ -239,14 +239,13 @@ class Privileges $privs[] = $currentGrant[1]; } } elseif ( - ! empty($_POST[$currentGrant[0]]) - && is_array($_POST[$currentGrant[0]]) + is_array($grantValue) && $grantValue !== [] && empty($_POST[$currentGrant[0] . '_none']) ) { // Required for proper escaping of ` (backtick) in a column name $grantCols = array_map( Util::backquote(...), - $_POST[$currentGrant[0]], + $grantValue, ); if ($enableHTML) {