Skip to content

Commit 4e563e6

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fix handling of overflowing invalid octal in tokenizer
2 parents 3f50922 + 641f961 commit 4e563e6

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

Zend/tests/bug71086.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ var_dump($highlightedString);
99
?>
1010
--EXPECT--
1111
string(169) "<code><span style="color: #000000">
12-
<span style="color: #0000BB">&lt;?php&nbsp;<br />&nbsp;</span><span style="color: #007700">09&nbsp;09&nbsp;09;</span>
12+
<span style="color: #0000BB">&lt;?php&nbsp;<br />&nbsp;09&nbsp;09&nbsp;09</span><span style="color: #007700">;</span>
1313
</span>
1414
</code>"

Zend/zend_language_scanner.l

+14-7
Original file line numberDiff line numberDiff line change
@@ -1820,25 +1820,32 @@ NEWLINE ("\r"|"\n"|"\r\n")
18201820
zend_bool is_octal = lnum[0] == '0';
18211821
zend_bool contains_underscores = (memchr(lnum, '_', len) != NULL);
18221822

1823+
if (contains_underscores) {
1824+
lnum = estrndup(lnum, len);
1825+
strip_underscores(lnum, &len);
1826+
}
1827+
18231828
/* Digits 8 and 9 are illegal in octal literals. */
18241829
if (is_octal) {
18251830
size_t i;
18261831
for (i = 0; i < len; i++) {
18271832
if (lnum[i] == '8' || lnum[i] == '9') {
18281833
zend_throw_exception(zend_ce_parse_error, "Invalid numeric literal", 0);
1829-
ZVAL_UNDEF(zendlval);
18301834
if (PARSER_MODE()) {
1835+
if (contains_underscores) {
1836+
efree(lnum);
1837+
}
1838+
ZVAL_UNDEF(zendlval);
18311839
RETURN_TOKEN(T_ERROR);
18321840
}
1833-
RETURN_TOKEN_WITH_VAL(T_LNUMBER);
1841+
1842+
/* Continue in order to determine if this is T_LNUMBER or T_DNUMBER. */
1843+
len = i;
1844+
break;
18341845
}
18351846
}
18361847
}
18371848

1838-
if (contains_underscores) {
1839-
lnum = estrndup(lnum, len);
1840-
strip_underscores(lnum, &len);
1841-
}
18421849

18431850
if (len < MAX_LENGTH_OF_LONG - 1) { /* Won't overflow */
18441851
errno = 0;
@@ -1850,7 +1857,7 @@ NEWLINE ("\r"|"\n"|"\r\n")
18501857
ZVAL_LONG(zendlval, ZEND_STRTOL(lnum, &end, 0));
18511858
if (errno == ERANGE) { /* Overflow */
18521859
errno = 0;
1853-
if (lnum[0] == '0') { /* octal overflow */
1860+
if (is_octal) { /* octal overflow */
18541861
ZVAL_DOUBLE(zendlval, zend_oct_strtod(lnum, (const char **)&end));
18551862
} else {
18561863
ZVAL_DOUBLE(zendlval, zend_strtod(lnum, (const char **)&end));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--TEST--
2+
Invalid octal number that overflows to double
3+
--FILE--
4+
<?php
5+
echo token_name(token_get_all('<?php 0177777777777777777777787')[1][0]), "\n";
6+
?>
7+
--EXPECT--
8+
T_DNUMBER

0 commit comments

Comments
 (0)