Skip to content

Commit 3fa80ff

Browse files
committed
More error messages and improved
1 parent 2a4d294 commit 3fa80ff

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

Zend/tests/zend_ini/zend_ini_parse_quantity_error.phpt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ $tests = [
1717
'0Z', # Invalid prefix
1818
'0XK', # Valid prefix with no value and multiplier
1919

20+
'++',
21+
'-+',
22+
'+ 25',
23+
'- 25',
24+
2025
# Null bytes
2126
" 123\x00K",
2227
"\x00 123K",
@@ -54,7 +59,7 @@ int(1024)
5459

5560
# "0X"
5661

57-
Warning: Invalid quantity: no digits after base prefix, interpreting as "0" for backwards compatibility in %s%ezend_ini_parse_quantity_error.php on line %d
62+
Warning: Invalid quantity "0X": no digits after base prefix, interpreting as "0" for backwards compatibility in %s%ezend_ini_parse_quantity_error.php on line %d
5863
int(0)
5964

6065
# "0Z"
@@ -67,6 +72,26 @@ int(0)
6772
Warning: Invalid quantity "0XK": no valid leading digits, interpreting as "0" for backwards compatibility in %s%ezend_ini_parse_quantity_error.php on line %d
6873
int(0)
6974

75+
# "++"
76+
77+
Warning: Invalid quantity "++": no valid leading digits, interpreting as "0" for backwards compatibility in %s%ezend_ini_parse_quantity_error.php on line %d
78+
int(0)
79+
80+
# "-+"
81+
82+
Warning: Invalid quantity "-+": no valid leading digits, interpreting as "0" for backwards compatibility in %s%ezend_ini_parse_quantity_error.php on line %d
83+
int(0)
84+
85+
# "+ 25"
86+
87+
Warning: Invalid quantity "+ 25": no valid leading digits, interpreting as "0" for backwards compatibility in %s%ezend_ini_parse_quantity_error.php on line %d
88+
int(0)
89+
90+
# "- 25"
91+
92+
Warning: Invalid quantity "- 25": no valid leading digits, interpreting as "0" for backwards compatibility in %s%ezend_ini_parse_quantity_error.php on line %d
93+
int(0)
94+
7095
# " 123\000K"
7196

7297
Warning: Invalid quantity " 123\x00K", interpreting as " 123K" for backwards compatibility in %s on line %d

Zend/zend_ini.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,11 +579,19 @@ static zend_ulong zend_ini_parse_quantity_internal(zend_string *value, zend_ini_
579579
++digits;
580580
}
581581

582-
/* TODO Handle cases such as ++25, --25, or white space after sign symbol?
582+
/* if there is no digit after +/- */
583583
if (!isdigit(digits[0])) {
584+
/* Escape the string to avoid null bytes and to make non-printable chars
585+
* visible */
586+
smart_str_append_escaped(&invalid, ZSTR_VAL(value), ZSTR_LEN(value));
587+
smart_str_0(&invalid);
588+
589+
*errstr = zend_strpprintf(0, "Invalid quantity \"%s\": no valid leading digits, interpreting as \"0\" for backwards compatibility",
590+
ZSTR_VAL(invalid.s));
584591

592+
smart_str_free(&invalid);
593+
return 0;
585594
}
586-
*/
587595

588596
int base = 0;
589597
if (digits[0] == '0' && !isdigit(digits[1])) {
@@ -621,7 +629,15 @@ static zend_ulong zend_ini_parse_quantity_internal(zend_string *value, zend_ini_
621629
}
622630
digits += 2;
623631
if (UNEXPECTED(digits == str_end)) {
624-
*errstr = zend_strpprintf(0, "Invalid quantity: no digits after base prefix, interpreting as \"0\" for backwards compatibility");
632+
/* Escape the string to avoid null bytes and to make non-printable chars
633+
* visible */
634+
smart_str_append_escaped(&invalid, ZSTR_VAL(value), ZSTR_LEN(value));
635+
smart_str_0(&invalid);
636+
637+
*errstr = zend_strpprintf(0, "Invalid quantity \"%s\": no digits after base prefix, interpreting as \"0\" for backwards compatibility",
638+
ZSTR_VAL(invalid.s));
639+
640+
smart_str_free(&invalid);
625641
return 0;
626642
}
627643
}

0 commit comments

Comments
 (0)