diff --git a/AbuseFilter.parser.php b/AbuseFilter.parser.php index cc9d7a864..6cbefe66a 100644 --- a/AbuseFilter.parser.php +++ b/AbuseFilter.parser.php @@ -1023,6 +1023,9 @@ class AbuseFilterParser { $this->move(); $r2 = new AFPData(); $this->doLevelSumRels( $r2 ); + if ( $this->mShortCircuit ) { + break; // The result doesn't matter. + } AbuseFilter::triggerLimiter(); $result = AFPData::compareOp( $result, $r2, $op ); } @@ -1039,6 +1042,9 @@ class AbuseFilterParser { $this->move(); $r2 = new AFPData(); $this->doLevelMulRels( $r2 ); + if ( $this->mShortCircuit ) { + break; // The result doesn't matter. + } if ( $op == '+' ) { $result = AFPData::sum( $result, $r2 ); } @@ -1059,6 +1065,9 @@ class AbuseFilterParser { $this->move(); $r2 = new AFPData(); $this->doLevelPow( $r2 ); + if ( $this->mShortCircuit ) { + break; // The result doesn't matter. + } $result = AFPData::mulRel( $result, $r2, $op, $this->mCur->pos ); } } @@ -1072,6 +1081,9 @@ class AbuseFilterParser { $this->move(); $expanent = new AFPData(); $this->doLevelBoolInvert( $expanent ); + if ( $this->mShortCircuit ) { + break; // The result doesn't matter. + } $result = AFPData::pow( $result, $expanent ); } } @@ -1083,6 +1095,9 @@ class AbuseFilterParser { if ( $this->mCur->type == AFPToken::TOP && $this->mCur->value == '!' ) { $this->move(); $this->doLevelSpecialWords( $result ); + if ( $this->mShortCircuit ) { + return; // The result doesn't matter. + } $result = AFPData::boolInvert( $result ); } else { $this->doLevelSpecialWords( $result ); @@ -1129,6 +1144,9 @@ class AbuseFilterParser { if ( $this->mCur->type == AFPToken::TOP && ( $op == "+" || $op == "-" ) ) { $this->move(); $this->doLevelListElements( $result ); + if ( $this->mShortCircuit ) { + return; // The result doesn't matter. + } if ( $op == '-' ) { $result = AFPData::unaryMinus( $result ); } diff --git a/tests/parserTests/shortcircuit.r b/tests/parserTests/shortcircuit.r new file mode 100644 index 000000000..4736e0800 --- /dev/null +++ b/tests/parserTests/shortcircuit.r @@ -0,0 +1 @@ +MATCH diff --git a/tests/parserTests/shortcircuit.t b/tests/parserTests/shortcircuit.t new file mode 100644 index 000000000..bec088f67 --- /dev/null +++ b/tests/parserTests/shortcircuit.t @@ -0,0 +1,2 @@ +/* The division by zero should not be executed and not crash the filter */ +true | 1/0 diff --git a/tests/phpunit/parserTest.php b/tests/phpunit/parserTest.php index 0a114f1bf..6bb8ff990 100644 --- a/tests/phpunit/parserTest.php +++ b/tests/phpunit/parserTest.php @@ -123,6 +123,8 @@ class AbuseFilterParserTest extends MediaWikiTestCase { array( 'a == b == c', 2 ), array( 'a in b + c in d + e in f', 3 ), array( 'true', 0 ), + array( 'a == a | c == d', 1 ), + array( 'a == b & c == d', 1 ), ); } }