Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ PHP NEWS
. Fixed bug GH-20051 (apache2 shutdowns when restart is requested during
preloading). (Arnaud, welcomycozyhom)

- Phar:
. Support reference values in Phar::mungServer(). (nielsdos)
. Invalid values now throw in Phar::mungServer() instead of being silently
ignored. (nielsdos)

- Standard:
. Fixed bug GH-19926 (reset internal pointer earlier while splicing array
while COW violation flag is still set). (alexandre-daubois)
Expand Down
7 changes: 7 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ PHP 8.6 UPGRADE NOTES
1. Backward Incompatible Changes
========================================

- Phar:
. Invalid values now throw in Phar::mungServer() instead of being silently
ignored.

========================================
2. New Features
========================================
Expand All @@ -44,6 +48,9 @@ PHP 8.6 UPGRADE NOTES
5. Changed Functions
========================================

- Phar:
. Phar::mungServer() now supports reference values.

========================================
6. New Functions
========================================
Expand Down
6 changes: 4 additions & 2 deletions ext/phar/phar_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ PHP_METHOD(Phar, mungServer)
phar_request_initialize();

ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(mungvalues), data) {

ZVAL_DEREF(data);
if (Z_TYPE_P(data) != IS_STRING) {
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");
RETURN_THROWS();
Expand All @@ -911,8 +911,10 @@ PHP_METHOD(Phar, mungServer)
PHAR_G(phar_SERVER_mung_list) |= PHAR_MUNG_SCRIPT_NAME;
} else if (zend_string_equals_literal(Z_STR_P(data), "SCRIPT_FILENAME")) {
PHAR_G(phar_SERVER_mung_list) |= PHAR_MUNG_SCRIPT_FILENAME;
} else {
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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be a ValueError as this is a programming error? Also specify the argument number of the array param

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as well, above should have been a TypeError it seems.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

phar is full of custom exceptions. Just looking at phar_object.c reveals several instances of BadMethodCallException for example which should ideally have been a ValueError [1], e.g. zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Unknown compression type specified");.

[1] Of course, phar predates ValueError etc...

If we want to make proper use of Value/TypeError in phar we should do an entire pass over the extension so it all remains internally consistent, rather than doing it on a case per case basis.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I know this. I was planning on doing a pass last year but didn't get round to it...

RETURN_THROWS();
}
// TODO Warning for invalid value?
} ZEND_HASH_FOREACH_END();
}
/* }}} */
Expand Down
15 changes: 15 additions & 0 deletions ext/phar/tests/invalid_string_phar_mungserver.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
Passing invalid string to Phar::mungServer()
--FILE--
<?php

$str = 'invalid';
try {
Phar::mungServer([&$str]);
} catch (PharException $e) {
echo $e->getMessage(), "\n";
}

?>
--EXPECT--
Invalid value passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME