diff --git a/Zend/zend_ast.c b/Zend/zend_ast.c index c908f6b18c7f..f495c4c8e3bb 100644 --- a/Zend/zend_ast.c +++ b/Zend/zend_ast.c @@ -1636,6 +1636,23 @@ static ZEND_COLD void zend_ast_export_qstr(smart_str *str, char quote, const zen } } +static ZEND_COLD void zend_ast_export_quoted_str(smart_str *str, zend_string *s) +{ + size_t i; + + for (i = 0; i < ZSTR_LEN(s); i++) { + if ((unsigned char) ZSTR_VAL(s)[i] < ' ') { + smart_str_appendc(str, '"'); + zend_ast_export_qstr(str, '"', s); + smart_str_appendc(str, '"'); + return; + } + } + smart_str_appendc(str, '\''); + zend_ast_export_str(str, s); + smart_str_appendc(str, '\''); +} + static ZEND_COLD void zend_ast_export_indent(smart_str *str, int indent) { while (indent > 0) { @@ -1907,9 +1924,7 @@ static ZEND_COLD void zend_ast_export_zval(smart_str *str, const zval *zv, int p str, Z_DVAL_P(zv), (int) EG(precision), /* zero_fraction */ true); break; case IS_STRING: - smart_str_appendc(str, '\''); - zend_ast_export_str(str, Z_STR_P(zv)); - smart_str_appendc(str, '\''); + zend_ast_export_quoted_str(str, Z_STR_P(zv)); break; case IS_ARRAY: { zend_long idx; @@ -1924,9 +1939,8 @@ static ZEND_COLD void zend_ast_export_zval(smart_str *str, const zval *zv, int p smart_str_appends(str, ", "); } if (key) { - smart_str_appendc(str, '\''); - zend_ast_export_str(str, key); - smart_str_appends(str, "' => "); + zend_ast_export_quoted_str(str, key); + smart_str_appends(str, " => "); } else { smart_str_append_long(str, idx); smart_str_appends(str, " => "); diff --git a/ext/pdo_dblib/dblib_driver.c b/ext/pdo_dblib/dblib_driver.c index 9f590c9071b6..389e3c805681 100644 --- a/ext/pdo_dblib/dblib_driver.c +++ b/ext/pdo_dblib/dblib_driver.c @@ -231,7 +231,7 @@ zend_string *dblib_handle_last_id(pdo_dbh_t *dbh, const zend_string *name) pdo_dblib_db_handle *H = (pdo_dblib_db_handle *)dbh->driver_data; RETCODE ret; - BYTE id[32]; + BYTE id[40]; size_t len; /* @@ -264,7 +264,7 @@ zend_string *dblib_handle_last_id(pdo_dbh_t *dbh, const zend_string *name) return NULL; } - len = dbconvert(NULL, (dbcoltype(H->link, 1)) , (dbdata(H->link, 1)) , (dbdatlen(H->link, 1)), SQLCHAR, (BYTE *)id, (DBINT)-1); + len = dbconvert(NULL, (dbcoltype(H->link, 1)) , (dbdata(H->link, 1)) , (dbdatlen(H->link, 1)), SQLCHAR, (BYTE *)id, (DBINT)sizeof(id)); dbcancel(H->link); return zend_string_init((const char *) id, len, 0); @@ -544,7 +544,6 @@ static int pdo_dblib_handle_factory(pdo_dbh_t *dbh, zval *driver_options) } if (i==nvers) { - printf("Invalid version '%s'\n", vars[5].optval); pdo_raise_impl_error(dbh, NULL, "HY000", "PDO_DBLIB: Invalid version specified in connection string."); goto cleanup; /* unknown version specified */ } diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index eff61659d078..a208741b1590 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -2477,9 +2477,20 @@ ZEND_METHOD(ReflectionParameter, __construct) switch (Z_TYPE_P(reference)) { case IS_STRING: { - zend_string *lcname = zend_string_tolower(Z_STR_P(reference)); - fptr = zend_hash_find_ptr(EG(function_table), lcname); - zend_string_release(lcname); + zend_string *fname = Z_STR_P(reference); + zend_string *lcname; + if (UNEXPECTED(ZSTR_VAL(fname)[0] == '\\')) { + /* Ignore leading "\" */ + ALLOCA_FLAG(use_heap) + ZSTR_ALLOCA_ALLOC(lcname, ZSTR_LEN(fname) - 1, use_heap); + zend_str_tolower_copy(ZSTR_VAL(lcname), ZSTR_VAL(fname) + 1, ZSTR_LEN(fname) - 1); + fptr = zend_fetch_function(lcname); + ZSTR_ALLOCA_FREE(lcname, use_heap); + } else { + lcname = zend_string_tolower(fname); + fptr = zend_fetch_function(lcname); + zend_string_release(lcname); + } if (!fptr) { zend_throw_exception_ex(reflection_exception_ptr, 0, "Function %s() does not exist", Z_STRVAL_P(reference)); diff --git a/ext/reflection/tests/ReflectionParameter_leading_backslash.phpt b/ext/reflection/tests/ReflectionParameter_leading_backslash.phpt new file mode 100644 index 000000000000..b0a7827c2764 --- /dev/null +++ b/ext/reflection/tests/ReflectionParameter_leading_backslash.phpt @@ -0,0 +1,17 @@ +--TEST-- +ReflectionParameter::__construct(): a leading "\" in the function name is ignored +--FILE-- +getName()); + +$p = new ReflectionParameter("demo", 0); +var_dump($p->getName()); + +?> +--EXPECT-- +string(3) "arg" +string(3) "arg" diff --git a/ext/standard/tests/assert/gh22290.phpt b/ext/standard/tests/assert/gh22290.phpt new file mode 100644 index 000000000000..e519a60f5572 --- /dev/null +++ b/ext/standard/tests/assert/gh22290.phpt @@ -0,0 +1,39 @@ +--TEST-- +GH-22290: AST pretty printing does not correctly handle strings containing NUL +--INI-- +zend.assertions=1 +assert.exception=1 +--FILE-- +getMessage(), PHP_EOL; +} + +try { + assert(["a\x00b" => 1] === []); +} catch (AssertionError $e) { + echo $e->getMessage(), PHP_EOL; +} + +try { + assert("tab\there" === ""); +} catch (AssertionError $e) { + echo $e->getMessage(), PHP_EOL; +} + +try { + assert(str_contains("plain", "zzz")); +} catch (AssertionError $e) { + echo $e->getMessage(), PHP_EOL; +} + +?> +--EXPECT-- +assert(!str_contains($string, "\000")) +assert(["a\000b" => 1] === []) +assert("tab\there" === '') +assert(str_contains('plain', 'zzz'))