Skip to content

Commit 9d9f979

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: Fix GH-20435: SensitiveParameter doesn't work for named argument passing to variadic parameter Fix GH-20442: Phar does not respect case-insensitiveness of __halt_compiler() when reading stub
2 parents aafb8a6 + 5087cf3 commit 9d9f979

File tree

5 files changed

+56
-34
lines changed

5 files changed

+56
-34
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
GH-20435 (SensitiveParameter doesn't work for named argument passing to variadic parameter)
3+
--FILE--
4+
<?php
5+
6+
function test($a, #[\SensitiveParameter] ...$x) {
7+
debug_print_backtrace();
8+
}
9+
10+
test(b: 1, a: 2, c: 3);
11+
12+
?>
13+
--EXPECTF--
14+
#0 %s(%d): test(2, b: Object(SensitiveParameterValue), c: Object(SensitiveParameterValue))

Zend/zend_builtin_functions.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,11 +1849,29 @@ static void debug_backtrace_get_args(zend_execute_data *call, zval *arg_array) /
18491849
if (ZEND_CALL_INFO(call) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS) {
18501850
zend_string *name;
18511851
zval *arg;
1852+
1853+
ZEND_ASSERT(call->func->common.fn_flags & ZEND_ACC_VARIADIC);
1854+
1855+
zend_attribute *attribute = zend_get_parameter_attribute_str(
1856+
call->func->common.attributes,
1857+
"sensitiveparameter",
1858+
sizeof("sensitiveparameter") - 1,
1859+
call->func->common.num_args
1860+
);
1861+
bool is_sensitive = attribute != NULL;
1862+
18521863
SEPARATE_ARRAY(arg_array);
18531864
ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(call->extra_named_params, name, arg) {
18541865
ZVAL_DEREF(arg);
1855-
Z_TRY_ADDREF_P(arg);
1856-
zend_hash_add_new(Z_ARRVAL_P(arg_array), name, arg);
1866+
if (is_sensitive) {
1867+
zval redacted_arg;
1868+
object_init_ex(&redacted_arg, zend_ce_sensitive_parameter_value);
1869+
zend_call_method_with_1_params(Z_OBJ_P(&redacted_arg), zend_ce_sensitive_parameter_value, &zend_ce_sensitive_parameter_value->constructor, "__construct", NULL, arg);
1870+
zend_hash_add_new(Z_ARRVAL_P(arg_array), name, &redacted_arg);
1871+
} else {
1872+
Z_TRY_ADDREF_P(arg);
1873+
zend_hash_add_new(Z_ARRVAL_P(arg_array), name, arg);
1874+
}
18571875
} ZEND_HASH_FOREACH_END();
18581876
}
18591877
}

ext/phar/phar.c

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,35 +1558,6 @@ zend_result phar_open_from_filename(char *fname, size_t fname_len, char *alias,
15581558
}
15591559
/* }}}*/
15601560

1561-
static inline char *phar_strnstr(const char *buf, size_t buf_len, const char *search, size_t search_len) /* {{{ */
1562-
{
1563-
const char *c;
1564-
ptrdiff_t so_far = 0;
1565-
1566-
if (buf_len < search_len) {
1567-
return NULL;
1568-
}
1569-
1570-
c = buf - 1;
1571-
1572-
do {
1573-
if (!(c = memchr(c + 1, search[0], buf_len - search_len - so_far))) {
1574-
return (char *) NULL;
1575-
}
1576-
1577-
so_far = c - buf;
1578-
1579-
if (so_far >= (buf_len - search_len)) {
1580-
return (char *) NULL;
1581-
}
1582-
1583-
if (!memcmp(c, search, search_len)) {
1584-
return (char *) c;
1585-
}
1586-
} while (1);
1587-
}
1588-
/* }}} */
1589-
15901561
/**
15911562
* Scan an open fp for the required __HALT_COMPILER(); ?> token and verify
15921563
* that the manifest is proper, then pass it to phar_parse_pharfile(). SUCCESS
@@ -1598,7 +1569,8 @@ static zend_result phar_open_from_fp(php_stream* fp, char *fname, size_t fname_l
15981569
static const char zip_magic[] = "PK\x03\x04";
15991570
static const char gz_magic[] = "\x1f\x8b\x08";
16001571
static const char bz_magic[] = "BZh";
1601-
char *pos, test = '\0';
1572+
const char *pos;
1573+
char test = '\0';
16021574
int recursion_count = 3; // arbitrary limit to avoid too deep or even infinite recursion
16031575
const int window_size = 1024;
16041576
char buffer[1024 + sizeof(token)]; /* a 1024 byte window + the size of the halt_compiler token (moving window) */
@@ -1747,14 +1719,14 @@ static zend_result phar_open_from_fp(php_stream* fp, char *fname, size_t fname_l
17471719
}
17481720

17491721
if (got >= 512) {
1750-
if (phar_is_tar(pos, fname)) {
1722+
if (phar_is_tar((char *) pos, fname)) { /* TODO: fix const correctness */
17511723
php_stream_rewind(fp);
17521724
return phar_parse_tarfile(fp, fname, fname_len, alias, alias_len, pphar, compression, error);
17531725
}
17541726
}
17551727
}
17561728

1757-
if (got > 0 && (pos = phar_strnstr(buffer, got + sizeof(token), token, sizeof(token)-1)) != NULL) {
1729+
if (got > 0 && (pos = php_memnistr(buffer, token, tokenlen, buffer + got + sizeof(token))) != NULL) {
17581730
halt_offset += (pos - buffer); /* no -tokenlen+tokenlen here */
17591731
return phar_parse_pharfile(fp, fname, fname_len, alias, alias_len, halt_offset, pphar, compression, error);
17601732
}

ext/phar/tests/files/gh20442.phar

144 Bytes
Binary file not shown.

ext/phar/tests/gh20442.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
GH-20442 (Phar does not respect case-insensitiveness of __halt_compiler() when reading stub)
3+
--EXTENSIONS--
4+
phar
5+
--FILE--
6+
<?php
7+
8+
$phar = new Phar(__DIR__.'/files/gh20442.phar');
9+
var_dump($phar->count());
10+
var_dump($phar->getStub());
11+
12+
?>
13+
--EXPECT--
14+
int(1)
15+
string(50) "<?php
16+
echo "Hello World!";
17+
__halt_compiler(); ?>
18+
"

0 commit comments

Comments
 (0)