Skip to content

Commit 3e715d3

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: 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 43b232a + 33a2acb commit 3e715d3

File tree

6 files changed

+62
-34
lines changed

6 files changed

+62
-34
lines changed

NEWS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ PHP NEWS
44

55
- Core:
66
. Sync all boost.context files with release 1.86.0. (mvorisek)
7+
. Fixed bug GH-20435 (SensitiveParameter doesn't work for named argument
8+
passing to variadic parameter). (ndossche)
79

810
- Date:
911
. Fix crashes when trying to instantiate uninstantiable classes via date
@@ -13,6 +15,10 @@ PHP NEWS
1315
. Fixed bug GH-20329 (opcache.file_cache broken with full interned string
1416
buffer). (Arnaud)
1517

18+
- Phar:
19+
. Fixed bug GH-20442 (Phar does not respect case-insensitiveness of
20+
__halt_compiler() when reading stub). (ndossche, TimWolla)
21+
1622
- Standard:
1723
. Fix memory leak in array_diff() with custom type checks. (ndossche)
1824

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
@@ -1798,11 +1798,29 @@ static void debug_backtrace_get_args(zend_execute_data *call, zval *arg_array) /
17981798
if (ZEND_CALL_INFO(call) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS) {
17991799
zend_string *name;
18001800
zval *arg;
1801+
1802+
ZEND_ASSERT(call->func->common.fn_flags & ZEND_ACC_VARIADIC);
1803+
1804+
zend_attribute *attribute = zend_get_parameter_attribute_str(
1805+
call->func->common.attributes,
1806+
"sensitiveparameter",
1807+
sizeof("sensitiveparameter") - 1,
1808+
call->func->common.num_args
1809+
);
1810+
bool is_sensitive = attribute != NULL;
1811+
18011812
SEPARATE_ARRAY(arg_array);
18021813
ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(call->extra_named_params, name, arg) {
18031814
ZVAL_DEREF(arg);
1804-
Z_TRY_ADDREF_P(arg);
1805-
zend_hash_add_new(Z_ARRVAL_P(arg_array), name, arg);
1815+
if (is_sensitive) {
1816+
zval redacted_arg;
1817+
object_init_ex(&redacted_arg, zend_ce_sensitive_parameter_value);
1818+
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);
1819+
zend_hash_add_new(Z_ARRVAL_P(arg_array), name, &redacted_arg);
1820+
} else {
1821+
Z_TRY_ADDREF_P(arg);
1822+
zend_hash_add_new(Z_ARRVAL_P(arg_array), name, arg);
1823+
}
18061824
} ZEND_HASH_FOREACH_END();
18071825
}
18081826
}

ext/phar/phar.c

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,35 +1592,6 @@ zend_result phar_open_from_filename(char *fname, size_t fname_len, char *alias,
15921592
}
15931593
/* }}}*/
15941594

1595-
static inline char *phar_strnstr(const char *buf, size_t buf_len, const char *search, size_t search_len) /* {{{ */
1596-
{
1597-
const char *c;
1598-
ptrdiff_t so_far = 0;
1599-
1600-
if (buf_len < search_len) {
1601-
return NULL;
1602-
}
1603-
1604-
c = buf - 1;
1605-
1606-
do {
1607-
if (!(c = memchr(c + 1, search[0], buf_len - search_len - so_far))) {
1608-
return (char *) NULL;
1609-
}
1610-
1611-
so_far = c - buf;
1612-
1613-
if (so_far >= (buf_len - search_len)) {
1614-
return (char *) NULL;
1615-
}
1616-
1617-
if (!memcmp(c, search, search_len)) {
1618-
return (char *) c;
1619-
}
1620-
} while (1);
1621-
}
1622-
/* }}} */
1623-
16241595
/**
16251596
* Scan an open fp for the required __HALT_COMPILER(); ?> token and verify
16261597
* that the manifest is proper, then pass it to phar_parse_pharfile(). SUCCESS
@@ -1632,7 +1603,8 @@ static zend_result phar_open_from_fp(php_stream* fp, char *fname, size_t fname_l
16321603
static const char zip_magic[] = "PK\x03\x04";
16331604
static const char gz_magic[] = "\x1f\x8b\x08";
16341605
static const char bz_magic[] = "BZh";
1635-
char *pos, test = '\0';
1606+
const char *pos;
1607+
char test = '\0';
16361608
int recursion_count = 3; // arbitrary limit to avoid too deep or even infinite recursion
16371609
const int window_size = 1024;
16381610
char buffer[1024 + sizeof(token)]; /* a 1024 byte window + the size of the halt_compiler token (moving window) */
@@ -1781,14 +1753,14 @@ static zend_result phar_open_from_fp(php_stream* fp, char *fname, size_t fname_l
17811753
}
17821754

17831755
if (got >= 512) {
1784-
if (phar_is_tar(pos, fname)) {
1756+
if (phar_is_tar((char *) pos, fname)) { /* TODO: fix const correctness */
17851757
php_stream_rewind(fp);
17861758
return phar_parse_tarfile(fp, fname, fname_len, alias, alias_len, pphar, compression, error);
17871759
}
17881760
}
17891761
}
17901762

1791-
if (got > 0 && (pos = phar_strnstr(buffer, got + sizeof(token), token, sizeof(token)-1)) != NULL) {
1763+
if (got > 0 && (pos = php_memnistr(buffer, token, tokenlen, buffer + got + sizeof(token))) != NULL) {
17921764
halt_offset += (pos - buffer); /* no -tokenlen+tokenlen here */
17931765
return phar_parse_pharfile(fp, fname, fname_len, alias, alias_len, halt_offset, pphar, compression, error);
17941766
}

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)