Skip to content

Commit aab5045

Browse files
authored
Add extra checks to Phar::mungServer() (#20141)
* Add extra checks to Phar::mungServer() * [ci skip] NEWS/UPGRADING
1 parent 67719e0 commit aab5045

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ PHP NEWS
2020
. Fixed bug GH-20051 (apache2 shutdowns when restart is requested during
2121
preloading). (Arnaud, welcomycozyhom)
2222

23+
- Phar:
24+
. Support reference values in Phar::mungServer(). (nielsdos)
25+
. Invalid values now throw in Phar::mungServer() instead of being silently
26+
ignored. (nielsdos)
27+
2328
- Standard:
2429
. Fixed bug GH-19926 (reset internal pointer earlier while splicing array
2530
while COW violation flag is still set). (alexandre-daubois)

UPGRADING

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ PHP 8.6 UPGRADE NOTES
1919
1. Backward Incompatible Changes
2020
========================================
2121

22+
- Phar:
23+
. Invalid values now throw in Phar::mungServer() instead of being silently
24+
ignored.
25+
2226
========================================
2327
2. New Features
2428
========================================
@@ -44,6 +48,9 @@ PHP 8.6 UPGRADE NOTES
4448
5. Changed Functions
4549
========================================
4650

51+
- Phar:
52+
. Phar::mungServer() now supports reference values.
53+
4754
========================================
4855
6. New Functions
4956
========================================

ext/phar/phar_object.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ PHP_METHOD(Phar, mungServer)
903903
phar_request_initialize();
904904

905905
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(mungvalues), data) {
906-
906+
ZVAL_DEREF(data);
907907
if (Z_TYPE_P(data) != IS_STRING) {
908908
zend_throw_exception_ex(phar_ce_PharException, 0, "Non-string value passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME");
909909
RETURN_THROWS();
@@ -917,8 +917,10 @@ PHP_METHOD(Phar, mungServer)
917917
PHAR_G(phar_SERVER_mung_list) |= PHAR_MUNG_SCRIPT_NAME;
918918
} else if (zend_string_equals_literal(Z_STR_P(data), "SCRIPT_FILENAME")) {
919919
PHAR_G(phar_SERVER_mung_list) |= PHAR_MUNG_SCRIPT_FILENAME;
920+
} else {
921+
zend_throw_exception_ex(phar_ce_PharException, 0, "Invalid value passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME");
922+
RETURN_THROWS();
920923
}
921-
// TODO Warning for invalid value?
922924
} ZEND_HASH_FOREACH_END();
923925
}
924926
/* }}} */
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Passing invalid string to Phar::mungServer()
3+
--FILE--
4+
<?php
5+
6+
$str = 'invalid';
7+
try {
8+
Phar::mungServer([&$str]);
9+
} catch (PharException $e) {
10+
echo $e->getMessage(), "\n";
11+
}
12+
13+
?>
14+
--EXPECT--
15+
Invalid value passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME

0 commit comments

Comments
 (0)