File tree Expand file tree Collapse file tree 4 files changed +20
-6
lines changed
Expand file tree Collapse file tree 4 files changed +20
-6
lines changed Original file line number Diff line number Diff line change 88 - 5.6
99 - 7.0
1010 - 7.1
11+ - 7.2
1112 - hhvm
1213
1314matrix :
Original file line number Diff line number Diff line change @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55and this project adheres to [ Semantic Versioning] ( http://semver.org/spec/v2.0.0.html ) .
66
77## [ Unreleased]
8+ ### Added
9+ - Add official support to PHP 7.2 (#71 )
10+ ### Fixed
11+ - Remove usage of create_function to avoid deprecations (#71 )
812
913## 0.8.3 - 2017-08-07
1014### Changed
Original file line number Diff line number Diff line change @@ -33,25 +33,23 @@ public function parse()
3333 array (". " , "" ),
3434 $ this ->expression
3535 );
36- // remove anything which could be a security issue
37- $ this ->expression = preg_replace ("/[^\d.+*%^|&~<>\/()-]/ " , "" , $ this ->expression );
3836
3937 return $ this ->compute ($ this ->expression );
4038 }
4139
42-
4340 /**
4441 * Converts error constants from string to int.
4542 *
4643 * @param string $expression e.g. E_ALL & ~E_DEPRECATED & ~E_NOTICE
47- * @return string convertes expression e.g. 32767 & ~8192 & ~8
44+ * @return string converted expression e.g. 32767 & ~8192 & ~8
4845 */
4946 private function convertErrorConstants ($ expression )
5047 {
5148 $ output = preg_replace_callback ("/(E_[a-zA-Z_]+)/ " , function ($ errorConstant ) {
5249 if (defined ($ errorConstant [1 ])) {
5350 return constant ($ errorConstant [1 ]);
5451 }
52+
5553 return $ errorConstant [0 ];
5654 }, $ expression );
5755
@@ -66,8 +64,11 @@ private function convertErrorConstants($expression)
6664 */
6765 private function compute ($ expression )
6866 {
69- $ compute = create_function ("" , "return " . $ expression . "; " );
67+ // catch anything which could be a security issue
68+ if (0 !== preg_match ("/[^\d.+*%^|&~<>\/()-]/ " , $ this ->expression )) {
69+ throw new \InvalidArgumentException ('Wrong value in error types config value ' );
70+ }
7071
71- return 0 + $ compute ( );
72+ return 0 + ( int ) eval ( ' return ' . $ expression . ' ; ' );
7273 }
7374}
Original file line number Diff line number Diff line change @@ -11,4 +11,12 @@ public function test_error_types_parser()
1111 $ ex = new ErrorTypesParser ('E_ALL & ~E_DEPRECATED & ~E_NOTICE ' );
1212 $ this ->assertEquals ($ ex ->parse (), E_ALL & ~E_DEPRECATED & ~E_NOTICE );
1313 }
14+
15+ public function test_error_types_parser_throws_exception_for_unwanted_values ()
16+ {
17+ $ ex = new ErrorTypesParser ('exec(something-dangerous) ' );
18+
19+ $ this ->setExpectedException ('\InvalidArgumentException ' );
20+ $ ex ->parse ();
21+ }
1422}
You can’t perform that action at this time.
0 commit comments