Skip to content

Commit 5865443

Browse files
Merge pull request #19262 from kamil-tekiela/Fix-privileges
Fix privileges Fixes #19177
2 parents 1741157 + ae01572 commit 5865443

3 files changed

Lines changed: 20 additions & 20 deletions

File tree

phpstan-baseline.neon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12062,7 +12062,7 @@ parameters:
1206212062

1206312063
-
1206412064
message: "#^Cannot access offset string on mixed\\.$#"
12065-
count: 2
12065+
count: 1
1206612066
path: src/Server/Privileges.php
1206712067

1206812068
-
@@ -12077,7 +12077,7 @@ parameters:
1207712077

1207812078
-
1207912079
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
12080-
count: 15
12080+
count: 14
1208112081
path: src/Server/Privileges.php
1208212082

1208312083
-

psalm-baseline.xml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10323,6 +10323,7 @@
1032310323
<code><![CDATA[$GLOBALS['pred_username']]]></code>
1032410324
<code><![CDATA[$extraData['db_wildcard_privs']]]></code>
1032510325
<code><![CDATA[$foundRows[]]]></code>
10326+
<code><![CDATA[$grantValue]]></code>
1032610327
<code><![CDATA[$host]]></code>
1032710328
<code><![CDATA[$hostnameLength]]></code>
1032810329
<code><![CDATA[$name]]></code>
@@ -10360,8 +10361,6 @@
1036010361
<code><![CDATA[mb_strrpos($exportUser, ';')]]></code>
1036110362
</PossiblyFalseOperand>
1036210363
<PossiblyInvalidArgument>
10363-
<code><![CDATA[$GLOBALS[$currentGrant[0]]]]></code>
10364-
<code><![CDATA[$GLOBALS[$currentGrant[0]]]]></code>
1036510364
<code><![CDATA[$_GET['username']]]></code>
1036610365
<code><![CDATA[$_POST['authentication_plugin']]]></code>
1036710366
<code><![CDATA[$_POST['authentication_plugin']]]></code>
@@ -10380,6 +10379,9 @@
1038010379
<code><![CDATA[$hashedPassword]]></code>
1038110380
<code><![CDATA[$oldUserGroup]]></code>
1038210381
</PossiblyInvalidArgument>
10382+
<PossiblyInvalidArrayOffset>
10383+
<code><![CDATA[$_POST[$currentGrant[0]]]]></code>
10384+
</PossiblyInvalidArrayOffset>
1038310385
<PossiblyInvalidCast>
1038410386
<code><![CDATA[$_GET['username']]]></code>
1038510387
<code><![CDATA[$_POST['authentication_plugin']]]></code>
@@ -10460,9 +10462,8 @@
1046010462
<code><![CDATA[$_POST['max_user_connections']]]></code>
1046110463
</RiskyCast>
1046210464
<RiskyTruthyFalsyComparison>
10463-
<code><![CDATA[empty($GLOBALS[$currentGrant[0] . '_none'])]]></code>
10464-
<code><![CDATA[empty($GLOBALS[$currentGrant[0] . '_none'])]]></code>
10465-
<code><![CDATA[empty($GLOBALS[$currentGrant[0]])]]></code>
10465+
<code><![CDATA[empty($_POST[$currentGrant[0] . '_none'])]]></code>
10466+
<code><![CDATA[empty($_POST[$currentGrant[0] . '_none'])]]></code>
1046610467
<code><![CDATA[empty($_POST['change_copy'])]]></code>
1046710468
<code><![CDATA[empty($_POST['nopass'])]]></code>
1046810469
<code><![CDATA[empty($_POST['pma_pw'])]]></code>

src/Server/Privileges.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -217,20 +217,20 @@ public function extractPrivInfo(array|null $row = null, bool $enableHTML = false
217217
$privs = [];
218218
$allPrivileges = true;
219219
foreach ($grants as $currentGrant) {
220-
if (
221-
($row === null || ! isset($row[$currentGrant[0]]))
222-
&& ($row !== null || ! isset($GLOBALS[$currentGrant[0]]))
223-
) {
220+
if ($row !== null && isset($row[$currentGrant[0]])) {
221+
$grantValue = $row[$currentGrant[0]];
222+
} elseif ($row === null && isset($_POST[$currentGrant[0]])) {
223+
$grantValue = $_POST[$currentGrant[0]];
224+
} else {
224225
continue;
225226
}
226227

227228
if (
228-
($row !== null && $row[$currentGrant[0]] === 'Y')
229+
($grantValue === 'Y')
229230
|| ($row === null
230-
&& ($GLOBALS[$currentGrant[0]] === 'Y'
231-
|| (is_array($GLOBALS[$currentGrant[0]])
232-
&& count($GLOBALS[$currentGrant[0]]) == $_REQUEST['column_count']
233-
&& empty($GLOBALS[$currentGrant[0] . '_none']))))
231+
&& is_array($grantValue)
232+
&& count($grantValue) == $_REQUEST['column_count']
233+
&& empty($_POST[$currentGrant[0] . '_none']))
234234
) {
235235
if ($enableHTML) {
236236
$privs[] = '<dfn title="' . $currentGrant[2] . '">'
@@ -239,14 +239,13 @@ public function extractPrivInfo(array|null $row = null, bool $enableHTML = false
239239
$privs[] = $currentGrant[1];
240240
}
241241
} elseif (
242-
! empty($GLOBALS[$currentGrant[0]])
243-
&& is_array($GLOBALS[$currentGrant[0]])
244-
&& empty($GLOBALS[$currentGrant[0] . '_none'])
242+
is_array($grantValue) && $grantValue !== []
243+
&& empty($_POST[$currentGrant[0] . '_none'])
245244
) {
246245
// Required for proper escaping of ` (backtick) in a column name
247246
$grantCols = array_map(
248247
Util::backquote(...),
249-
$GLOBALS[$currentGrant[0]],
248+
$grantValue,
250249
);
251250

252251
if ($enableHTML) {

0 commit comments

Comments
 (0)