com php-src: Fixed bug #70430: Zend/tests/bug70430.phpt Zend/zend_language_parser.y
| From: | Anatol Belski | Date: | Sun, 18 Oct 2015 10:41:26 +0000 |
| Subject: | com php-src: Fixed bug #70430: Zend/tests/bug70430.phpt Zend/zend_language_parser.y | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-89520@lists.php.net to get a copy of this message | ||
Commit: 5576aee84faa4ecc4ffb8f2ea4809c73b4601e2d
Author: Nikita Popov <nikic@php.net> Mon, 12 Oct 2015 22:05:19 +0200
Committer: Anatol Belski <ab@php.net> Sun, 18 Oct 2015 12:41:26 +0200
Parents: d449c527bc168a8aef4779a541c84f3b93bc514a
Branches: PHP-7.0.0
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=5576aee84faa4ecc4ffb8f2ea4809c73b4601e2d
Log:
Fixed bug #70430
Bugs:
https://bugs.php.net/70430
Changed paths:
A Zend/tests/bug70430.phpt
M Zend/zend_language_parser.y
Diff:
diff --git a/Zend/tests/bug70430.phpt b/Zend/tests/bug70430.phpt
new file mode 100644
index 0000000..5998365
--- /dev/null
+++ b/Zend/tests/bug70430.phpt
@@ -0,0 +1,10 @@
+--TEST--
+Bug #70430: Stack buffer overflow in zend_language_parser()
+--FILE--
+<?php
+
+$"*** Testing function() : ***\n";
+
+?>
+--EXPECTF--
+Parse error: syntax error, unexpected '"*** Testing function() : ***'
(T_CONSTANT_ENCAPSED_STRING), expecting variable (T_VARIABLE) or '{' or '$' in
%s on line %d
diff --git a/Zend/zend_language_parser..y b/Zend/zend_language_parser.y
index a253a76..3fc6494 100644
--- a/Zend/zend_language_parser.y
+++ b/Zend/zend_language_parser.y
@@ -1278,20 +1278,30 @@ isset_variable:
would have been. */
static YYSIZE_T zend_yytnamerr(char *yyres, const char *yystr)
{
- if (!yyres) {
- return yystrlen(yystr);
+ /* CG(parse_error) states:
+ * 0 => yyres = NULL, yystr is the unexpected token
+ * 1 => yyres = NULL, yystr is one of the expected tokens
+ * 2 => yyres != NULL, yystr is the unexpected token
+ * 3 => yyres != NULL, yystr is one of the expected tokens
+ */
+ if (yyres && CG(parse_error) < 2) {
+ CG(parse_error) = 2;
}
- if (CG(parse_error) == 0) {
+
+ if (CG(parse_error) % 2 == 0) {
+ /* The unexpected token */
char buffer[120];
const unsigned char *end, *str, *tok1 = NULL, *tok2 = NULL;
unsigned int len = 0, toklen = 0, yystr_len;
- CG(parse_error) = 1;
+ CG(parse_error)++;
if (LANG_SCNG(yy_text)[0] == 0 &&
LANG_SCNG(yy_leng) == 1 &&
memcmp(yystr, "\"end of file\"", sizeof("\"end of
file\"") - 1) == 0) {
- yystpcpy(yyres, "end of file");
+ if (yyres) {
+ yystpcpy(yyres, "end of file");
+ }
return sizeof("end of file")-1;
}
@@ -1312,14 +1322,22 @@ static YYSIZE_T zend_yytnamerr(char *yyres, const char *yystr)
} else {
len = (end - str) > 30 ? 30 : (end - str);
}
- if (toklen) {
- snprintf(buffer, sizeof(buffer), "'%.*s' %.*s", len, str, toklen, tok1);
- } else {
- snprintf(buffer, sizeof(buffer), "'%.*s'", len, str);
+ if (yyres) {
+ if (toklen) {
+ snprintf(buffer, sizeof(buffer), "'%.*s' %.*s", len, str, toklen, tok1);
+ } else {
+ snprintf(buffer, sizeof(buffer), "'%.*s'", len, str);
+ }
+ yystpcpy(yyres, buffer);
}
- yystpcpy(yyres, buffer);
return len + (toklen ? toklen + 1 : 0) + 2;
}
+
+ /* One of the expected tokens */
+ if (!yyres) {
+ return yystrlen(yystr) - (*yystr == '"' ? 2 : 0);
+ }
+
if (*yystr == '"') {
YYSIZE_T yyn = 0;
const char *yyp = yystr;