Force full evaluation of filter in FilterEvaluator->getUsedVars()

In some cases, evaluation short-circuits when getting a list of
used variables resulting in an incomplete array of variables. This
subsequently causes issues when using those arrays for validation
checks (eg. if protected variables are used).

- Force full evaluation by setting `mAllowShort` to false

Bug: T364485
Change-Id: Idf2112d9ebf63846cde3ce9b8a8ade0ed909505d
This commit is contained in:
STran 2024-06-10 10:56:10 -07:00
parent 25e1b8f8eb
commit f5d7b68908
2 changed files with 15 additions and 3 deletions

View file

@ -454,7 +454,13 @@ class FilterEvaluator {
*/
public function getUsedVars( $filter ) {
$this->resetState();
$this->evaluateExpression( $filter );
$cachedAllowShort = $this->mAllowShort;
try {
$this->mAllowShort = false;
$this->evaluateExpression( $filter );
} finally {
$this->mAllowShort = $cachedAllowShort;
}
return array_unique( $this->usedVars );
}

View file

@ -1170,7 +1170,13 @@ class ParserTest extends ParserTestCase {
$parser = $this->getParser();
/** @var FilterEvaluator $wrapper */
$wrapper = TestingAccessWrapper::newFromObject( $parser );
$this->assertSame( [ 'user_name' ], $wrapper->getUsedVars( 'ip_in_range( user_name, "1.2.3.4" )' ) );
$this->assertSame( [ 'user_name' ], $wrapper->getUsedVars( 'ip_in_range( USER_NAME, "1.2.3.4" )' ) );
$this->assertSame(
[ 'action', 'user_name' ],
$wrapper->getUsedVars( 'action = "edit" & ip_in_range( user_name, "1.2.3.4" )' )
);
$this->assertSame(
[ 'action', 'user_name' ],
$wrapper->getUsedVars( 'action = "edit" & ip_in_range( USER_NAME, "1.2.3.4" )' )
);
}
}