com php-src: Fixed bug #77844: NEWS Zend/zend_ini_parser. y ext/standard/tests/general_functions/bug77844 .phpt
| From: | Nikita Popov | Date: | Mon, 08 Apr 2019 09:11:58 +0000 |
| Subject: | com php-src: Fixed bug #77844: NEWS Zend/zend_ini_parser. y ext/standard/tests/general_functions/bug77844 .phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-105565@lists.php.net to get a copy of this message | ||
Commit: eea61cda7df1466a1f40a17c21b65901c1c68ce0
Author: Nikita Popov <nikita.ppv@gmail.com> Mon, 8 Apr 2019 11:11:58 +0200
Parents: d1d692abe71b04177747758237249253b175b8c2
Branches: PHP-7.2 PHP-7.3 PHP-7.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=eea61cda7df1466a1f40a17c21b65901c1c68ce0
Log:
Fixed bug #77844
We should probably return an integer result from the operation in
typed mode, right now the result is always a string.
Bugs:
https://bugs.php.net/77844
Changed paths:
M NEWS
M Zend/zend_ini_parser.y
A ext/standard/tests/general_functions/bug77844.phpt
Diff:
diff --git a/NEWS b/NEWS
index d355778..ed3f73a 100644
--- a/NEWS
+++ b/NEWS
@@ -30,6 +30,8 @@ PHP NEWS
- Standard:
. Fixed bug #77680 (recursive mkdir on ftp stream wrapper is incorrect).
(Vlad Temian)
+ . Fixed bug #77844 (Crash due to null pointer in parse_ini_string with
+ INI_SCANNER_TYPED). (Nikita)
04 Apr 2019, PHP 7.2.17
diff --git a/Zend/zend_ini_parser.y b/Zend/zend_ini_parser.y
index 768486c..a0ceb2c 100644
--- a/Zend/zend_ini_parser.y
+++ b/Zend/zend_ini_parser.y
@@ -48,6 +48,22 @@ int ini_parse(void);
#define ZEND_SYSTEM_INI CG(ini_parser_unbuffered_errors)
+static int get_int_val(zval *op) {
+ switch (Z_TYPE_P(op)) {
+ case IS_LONG:
+ return Z_LVAL_P(op);
+ case IS_DOUBLE:
+ return (int)Z_DVAL_P(op);
+ case IS_STRING:
+ {
+ int val = atoi(Z_STRVAL_P(op));
+ zend_string_free(Z_STR_P(op));
+ return val;
+ }
+ EMPTY_SWITCH_DEFAULT_CASE()
+ }
+}
+
/* {{{ zend_ini_do_op()
*/
static void zend_ini_do_op(char type, zval *result, zval *op1, zval *op2)
@@ -57,22 +73,8 @@ static void zend_ini_do_op(char type, zval *result, zval *op1, zval *op2)
int str_len;
char str_result[MAX_LENGTH_OF_LONG+1];
- if (IS_LONG == Z_TYPE_P(op1)) {
- i_op1 = Z_LVAL_P(op1);
- } else {
- i_op1 = atoi(Z_STRVAL_P(op1));
- zend_string_free(Z_STR_P(op1));
- }
- if (op2) {
- if (IS_LONG == Z_TYPE_P(op2)) {
- i_op2 = Z_LVAL_P(op2);
- } else {
- i_op2 = atoi(Z_STRVAL_P(op2));
- zend_string_free(Z_STR_P(op2));
- }
- } else {
- i_op2 = 0;
- }
+ i_op1 = get_int_val(op1);
+ i_op2 = op2 ? get_int_val(op2) : 0;
switch (type) {
case '|':
diff --git a/ext/standard/tests/general_functions/bug77844.phpt
b/ext/standard/tests/general_functions/bug77844.phpt
new file mode 100644
index 0000000..a8b6bf3
--- /dev/null
+++ b/ext/standard/tests/general_functions/bug77844.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Bug #77844: Crash due to null pointer in parse_ini_string with INI_SCANNER_TYPED
+--FILE--
+<?php
+
+$ini = <<<INI
+val1=3.7&2
+val2=2&3.7
+INI;
+var_dump(parse_ini_string($ini, true, INI_SCANNER_TYPED));
+
+?>
+--EXPECT--
+array(2) {
+ ["val1"]=>
+ string(1) "2"
+ ["val2"]=>
+ string(1) "2"
+}