Skip to content
Merged
26 changes: 20 additions & 6 deletions Zend/zend_ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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, " => ");
Expand Down
5 changes: 2 additions & 3 deletions ext/pdo_dblib/dblib_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/*
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 */
}
Expand Down
17 changes: 14 additions & 3 deletions ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
17 changes: 17 additions & 0 deletions ext/reflection/tests/ReflectionParameter_leading_backslash.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
ReflectionParameter::__construct(): a leading "\" in the function name is ignored
--FILE--
<?php

function demo(string $arg) {}

$p = new ReflectionParameter("\\demo", 0);
var_dump($p->getName());

$p = new ReflectionParameter("demo", 0);
var_dump($p->getName());

?>
--EXPECT--
string(3) "arg"
string(3) "arg"
39 changes: 39 additions & 0 deletions ext/standard/tests/assert/gh22290.phpt
Original file line number Diff line number Diff line change
@@ -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--
<?php

try {
$string = "Foo\x00bar";
assert(!str_contains($string, "\x00"));
} catch (AssertionError $e) {
echo $e->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'))
Loading