mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-24 14:13:54 +00:00
Always evaluate the offset when retrieving array elements
Even if the array is DUNDEFINED, we need to check the offset to ensure that it's valid. Bug: T237351 Change-Id: Ibfa360c4ae1d80abe14d9fdf66991b76cb5954df
This commit is contained in:
parent
cb6f3500b1
commit
8ad4ecd31d
|
@ -171,6 +171,9 @@ class AbuseFilterCachingParser extends AbuseFilterParser {
|
|||
list( $array, $offset ) = $node->children;
|
||||
|
||||
$array = $this->evalNode( $array );
|
||||
// Note: we MUST evaluate the offset to ensure it is valid, regardless
|
||||
// of $array!
|
||||
$offset = $this->evalNode( $offset )->toInt();
|
||||
|
||||
if ( $array->getType() === AFPData::DUNDEFINED ) {
|
||||
return new AFPData( AFPData::DUNDEFINED );
|
||||
|
@ -180,8 +183,6 @@ class AbuseFilterCachingParser extends AbuseFilterParser {
|
|||
throw new AFPUserVisibleException( 'notarray', $node->position, [] );
|
||||
}
|
||||
|
||||
$offset = $this->evalNode( $offset )->toInt();
|
||||
|
||||
$array = $array->toArray();
|
||||
if ( count( $array ) <= $offset ) {
|
||||
throw new AFPUserVisibleException( 'outofbounds', $node->position,
|
||||
|
|
|
@ -301,6 +301,8 @@ class AbuseFilterParserTest extends AbuseFilterParserTestCase {
|
|||
[ 'a[1] := 5', 'getVarValue' ],
|
||||
[ 'a[] := 5', 'getVarValue' ],
|
||||
[ 'a = 5', 'getVarValue' ],
|
||||
[ 'timestamp[a]', 'getVarValue' ],
|
||||
[ 'x := []; x[a] := 1', 'getVarValue' ],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue