Skip to content

Deprecate implicit bool to string coercion #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
dce5e56
Fix #81708: UAF due to php_filter_float() failing for ints
cmb69 Jan 31, 2022
82f1bf1
Fix #81708: UAF due to php_filter_float() failing for ints
cmb69 Jan 31, 2022
61b276c
Merge branch 'PHP-7.4' into PHP-8.0
smalyshev Feb 14, 2022
414d562
Merge branch 'PHP-8.0' into PHP-8.1
smalyshev Feb 14, 2022
8b1b6ae
Merge branch 'PHP-8.1'
smalyshev Feb 14, 2022
93a8d5c
Fix bug GH-8058 - mysqlnd segfault when prepare fails
kamil-tekiela Feb 8, 2022
2bae4e8
Merge branch 'PHP-8.0' into PHP-8.1
kamil-tekiela Feb 14, 2022
b582427
Merge branch 'PHP-8.1'
kamil-tekiela Feb 14, 2022
d13ceb7
Add fix to NEWS
derickr Feb 14, 2022
f810594
Merge branch 'PHP-7.4' into PHP-8.0
derickr Feb 14, 2022
7add0da
Merge branch 'PHP-8.0' into PHP-8.1
derickr Feb 14, 2022
7d6b961
Merge branch 'PHP-8.1'
derickr Feb 14, 2022
0fab520
Fix zend_register_internal_class_ex alias generation (#8091)
TysonAndre Feb 14, 2022
325bcf9
Prepare for 7.4.29
derickr Feb 15, 2022
6fbf5a6
Merge branch 'PHP-7.4' into PHP-8.0
derickr Feb 15, 2022
0e32d3f
Merge branch 'PHP-8.0' into PHP-8.1
derickr Feb 15, 2022
0e65e43
Merge branch 'PHP-8.1'
derickr Feb 15, 2022
e98a7a6
Fix bugtracker URL
cmb69 Feb 15, 2022
720d6fa
Merge branch 'PHP-8.0' into PHP-8.1
cmb69 Feb 15, 2022
1c381a7
Merge branch 'PHP-8.1'
cmb69 Feb 15, 2022
bfe9531
Initialize int_codepoint in parse_code_point_param()
nikic Feb 16, 2022
40e0bdb
Merge branch 'PHP-8.0' into PHP-8.1
nikic Feb 16, 2022
06de112
Merge branch 'PHP-8.1'
nikic Feb 16, 2022
f06ac9a
Fix GH-7939: Cannot unserialize IntlTimeZone objects
cmb69 Jan 20, 2022
8f5480e
Release lock and protect SHM before replaying warnings
dstogov Feb 17, 2022
90ca8f9
Merge branch 'PHP-8.0' into PHP-8.1
dstogov Feb 17, 2022
529f9f8
Merge branch 'PHP-8.1'
dstogov Feb 17, 2022
7e8257f
Disable ASSIGN optimization for values inferred for fatal errors.
dstogov Feb 18, 2022
ace00fa
Merge branch 'PHP-8.1'
dstogov Feb 18, 2022
84a638a
Fix memory leak
dstogov Feb 18, 2022
22328f6
Merge branch 'PHP-8.0' into PHP-8.1
dstogov Feb 18, 2022
90e4d54
Merge branch 'PHP-8.1'
dstogov Feb 18, 2022
3198b87
JIT: Fix register allocation
dstogov Feb 18, 2022
afbb9b9
Merge branch 'PHP-8.0' into PHP-8.1
dstogov Feb 18, 2022
55b4dde
Merge branch 'PHP-8.1'
dstogov Feb 18, 2022
2753b45
[ci skip] Don't run GitHub actions on forks
iluuu1994 Feb 18, 2022
19063a8
Fix null static_variable_ptr for uncalled fake closures
iluuu1994 Feb 17, 2022
7d8e3da
Merge branch 'PHP-8.1'
iluuu1994 Feb 19, 2022
f3cc497
Deprecate implicit bool to string coercion
iluuu1994 Feb 20, 2022
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
1 change: 1 addition & 0 deletions .github/workflows/close-needs-feedback.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:

jobs:
build:
if: github.repository_owner == 'php'
runs-on: ubuntu-latest
steps:
- name: Close old issues that need feedback
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/close-stale-prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:

jobs:
stale:
if: github.repository_owner == 'php'
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/remove-needs-feedback.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
build:
if: "contains(github.event.issue.labels.*.name, 'Status: Needs Feedback') && github.event.issue.user.login == github.event.sender.login"
if: "github.repository_owner == 'php' && contains(github.event.issue.labels.*.name, 'Status: Needs Feedback') && github.event.issue.user.login == github.event.sender.login"
runs-on: ubuntu-latest
steps:
- uses: actions-ecosystem/action-remove-labels@v1
Expand Down
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ PHP NEWS

- Intl:
. Update all grandfathered language tags with preferred values
. Fixed GH-7939 (Cannot unserialize IntlTimeZone objects). (cmb)

- OCI8:
. Added oci8.prefetch_lob_size directive to tune LOB query performance
Expand Down
8 changes: 8 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ PHP 8.2 UPGRADE NOTES
9. Other Changes to Extensions
========================================

- Intl:
. IntlBreakIterator, IntlRuleBasedBreakIterator, IntlCodePointBreakIterator,
IntlPartsIterator, IntlCalendar, IntlCalendar, Collator, IntlIterator,
UConverter, IntlDateFormatter, IntlDatePatternGenerator, MessageFormatter,
ResourceBundle, Spoofchecker, IntlTimeZone and Transliterator instances are
no longer serializable. Previously, they could be serialized, but
unserialization yielded unusable objects or failed.

- OCI8:
. The minimum Oracle Client library version required is now 11.2.

Expand Down
2 changes: 2 additions & 0 deletions Zend/Optimizer/dfa_pass.c
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,7 @@ void zend_dfa_optimize_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx

if (src_var >= 0
&& !(ssa->var_info[src_var].type & MAY_BE_REF)
&& (ssa->var_info[src_var].type & (MAY_BE_UNDEF|MAY_BE_ANY))
&& ssa->vars[src_var].definition >= 0
&& ssa->ops[ssa->vars[src_var].definition].result_def == src_var
&& ssa->ops[ssa->vars[src_var].definition].result_use < 0
Expand Down Expand Up @@ -1463,6 +1464,7 @@ void zend_dfa_optimize_op_array(zend_op_array *op_array, zend_optimizer_ctx *ctx
if ((opline->op2_type & (IS_TMP_VAR|IS_VAR))
&& src_var >= 0
&& !(ssa->var_info[src_var].type & MAY_BE_REF)
&& (ssa->var_info[src_var].type & (MAY_BE_UNDEF|MAY_BE_ANY))
&& ssa->vars[src_var].definition >= 0
&& ssa->ops[ssa->vars[src_var].definition].result_def == src_var
&& ssa->ops[ssa->vars[src_var].definition].result_use < 0
Expand Down
2 changes: 2 additions & 0 deletions Zend/tests/017.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ string(5) "array"
int(%d)
string(5) "array"
int(%d)

Deprecated: Implicit bool to string coercion is deprecated in %s on line %d
bool(false)
string(5) "array"
int(%d)
Expand Down
3 changes: 2 additions & 1 deletion Zend/tests/call_user_func_strict_arginfo_check.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ namespace Foo;
var_dump(call_user_func('strlen', false));

?>
--EXPECT--
--EXPECTF--
Deprecated: Implicit bool to string coercion is deprecated in %s on line %d
int(0)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
Memory leak when resume an already running generator
--FILE--
<?php
function gen() {
$g = yield;
$g->send($g);
}
$gen = gen();
try {
$gen->send($gen);
} catch (Throwable $e) {
echo $e->getMessage() . "\n";
}
?>
--EXPECT--
Cannot resume an already running generator
22 changes: 22 additions & 0 deletions Zend/tests/gh8083.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
GH-8083 (var_dump() on closure with static variable segfaults)
--FILE--
<?php

function func() {
static $i;
}

$x = func(...);

var_dump($x);

?>
--EXPECT--
object(Closure)#1 (1) {
["static"]=>
array(1) {
["i"]=>
NULL
}
}
2 changes: 2 additions & 0 deletions Zend/tests/type_declarations/scalar_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,11 @@ string(%d) "%d"
string(3) "NAN"

*** Trying bool(true)
E_DEPRECATED: Implicit bool to string coercion is deprecated on line 16
string(1) "1"

*** Trying bool(false)
E_DEPRECATED: Implicit bool to string coercion is deprecated on line 16
string(0) ""

*** Trying NULL
Expand Down
2 changes: 2 additions & 0 deletions Zend/tests/type_declarations/scalar_return_basic_64bit.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,10 @@ string(19) "9223372036854775807"
*** Trying float(NAN)
string(3) "NAN"
*** Trying bool(true)
E_DEPRECATED: Implicit bool to string coercion is deprecated on line 16
string(1) "1"
*** Trying bool(false)
E_DEPRECATED: Implicit bool to string coercion is deprecated on line 16
string(0) ""
*** Trying NULL
*** Caught {closure}(): Return value must be of type string, null returned in %s on line %d
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ INF => "INF"
"42x" => "42x"
"x" => "x"
"" => ""
true => "1"
false => ""
true => "1" (Implicit bool to string coercion is deprecated)
false => "" (Implicit bool to string coercion is deprecated)
null => Argument ... must be of type array|string, null given
[] => []
new stdClass => Argument ... must be of type array|string, stdClass given
Expand Down
3 changes: 3 additions & 0 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,9 @@ ZEND_API bool ZEND_FASTCALL zend_parse_arg_str_weak(zval *arg, zend_string **des
if (UNEXPECTED(Z_TYPE_P(arg) == IS_NULL) && !zend_null_arg_deprecated("string", arg_num)) {
return 0;
}
if (UNEXPECTED(Z_TYPE_P(arg) == IS_TRUE || Z_TYPE_P(arg) == IS_FALSE)) {
zend_error(E_DEPRECATED, "Implicit bool to string coercion is deprecated");
}
convert_to_string(arg);
*dest = Z_STR_P(arg);
} else if (UNEXPECTED(Z_TYPE_P(arg) == IS_OBJECT)) {
Expand Down
1 change: 1 addition & 0 deletions Zend/zend_generators.c
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,7 @@ ZEND_METHOD(Generator, send)
root = zend_generator_get_current(generator);
/* Put sent value in the target VAR slot, if it is used */
if (root->send_target) {
zval_ptr_dtor(root->send_target);
ZVAL_COPY(root->send_target, value);
}

Expand Down
2 changes: 1 addition & 1 deletion build/gen_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -1756,7 +1756,7 @@ function (Name $item) {
}

if ($this->alias) {
$code .= "\tzend_register_class_alias(\"" . str_replace("\\", "_", $this->alias) . "\", class_entry);\n";
$code .= "\tzend_register_class_alias(\"" . str_replace("\\", "\\\\", $this->alias) . "\", class_entry);\n";
}

foreach ($this->enumCaseInfos as $enumCase) {
Expand Down
2 changes: 1 addition & 1 deletion ext/filter/logical_filters.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,10 +444,10 @@ void php_filter_float(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */

switch (is_numeric_string(num, p - num, &lval, &dval, 0)) {
case IS_LONG:
zval_ptr_dtor(value);
if ((min_range_set && (lval < min_range)) || (max_range_set && (lval > max_range))) {
goto error;
}
zval_ptr_dtor(value);
ZVAL_DOUBLE(value, (double)lval);
break;
case IS_DOUBLE:
Expand Down
18 changes: 18 additions & 0 deletions ext/filter/tests/bug81708.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Bug #81708 (UAF due to php_filter_float() failing for ints)
--EXTENSIONS--
filter
--INI--
opcache.enable_cli=0
--FILE--
<?php
$input = "+" . str_repeat("1", 2); // avoid string interning
filter_var(
$input,
FILTER_VALIDATE_FLOAT,
["options" => ['min_range' => -1, 'max_range' => 1]]
);
var_dump($input);
?>
--EXPECT--
string(3) "+11"
4 changes: 4 additions & 0 deletions ext/iconv/tests/bug48147.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ bool(false)
string(10) "aa%C3%B8aa"

Notice: iconv(): Detected an incomplete multibyte character in input string in %s on line %d

Deprecated: Implicit bool to string coercion is deprecated in %s on line %d
string(0) ""
string(8) "%C3%B8aa"

Notice: iconv(): Detected an incomplete multibyte character in input string in %s on line %d

Deprecated: Implicit bool to string coercion is deprecated in %s on line %d
string(0) ""
2 changes: 2 additions & 0 deletions ext/iconv/tests/iconv_mime_decode.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ do_regression_test();
(32) "Subject: Prüfung PrüfungkůÔńÓlet"
(31) "Subject: PrüfungPrüfungkůÔńÓlet"
2: iconv_mime_decode(): Malformed string
8192: Implicit bool to string coercion is deprecated
(0) ""
(27) "From: サンプル文字列サンプル文字列日本語テキスト"
(31) "Subject: PrüfungPrüfungkůÔńÓlet"
(32) "Subject: Prüfung PrüfungkůÔńÓlet"
(100) "Subject: =?ISO-8859-1?Q?Pr=FCfung?==?ISO-8859-1*de_DE?Q?Pr=FCfung?==?ISO-8859-2?Q?k=F9=D4=F1=D3let?="
2: iconv_mime_decode(): Malformed string
8192: Implicit bool to string coercion is deprecated
(0) ""
(27) "From: サンプル文字列サンプル文字列日本語テキスト"
(31) "Subject: PrüfungPrüfungkůÔńÓlet"
Expand Down
3 changes: 3 additions & 0 deletions ext/intl/breakiterator/breakiterator.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

/** @generate-class-entries */

/** @not-serializable */
class IntlBreakIterator implements IteratorAggregate
{
/** @tentative-return-type */
Expand Down Expand Up @@ -69,6 +70,7 @@ public function setText(string $text): ?bool {} // TODO return false instead of
public function getIterator(): Iterator {}
}

/** @not-serializable */
class IntlRuleBasedBreakIterator extends IntlBreakIterator
{
public function __construct(string $rules, bool $compiled = false) {}
Expand All @@ -86,6 +88,7 @@ public function getRuleStatus(): int {}
public function getRuleStatusVec(): array|false {}
}

/** @not-serializable */
class IntlCodePointBreakIterator extends IntlBreakIterator
{
/** @tentative-return-type */
Expand Down
5 changes: 4 additions & 1 deletion ext/intl/breakiterator/breakiterator_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 1979da7ee2fa55b27f1c91bb4e0ddc37e8505b08 */
* Stub hash: 724e0c36ee113b67906cc9a8cea23781f0a961bf */

ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(arginfo_class_IntlBreakIterator_createCharacterInstance, 0, 0, IntlBreakIterator, 1)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, locale, IS_STRING, 1, "null")
Expand Down Expand Up @@ -161,6 +161,7 @@ static zend_class_entry *register_class_IntlBreakIterator(zend_class_entry *clas

INIT_CLASS_ENTRY(ce, "IntlBreakIterator", class_IntlBreakIterator_methods);
class_entry = zend_register_internal_class_ex(&ce, NULL);
class_entry->ce_flags |= ZEND_ACC_NOT_SERIALIZABLE;
zend_class_implements(class_entry, 1, class_entry_IteratorAggregate);

return class_entry;
Expand All @@ -172,6 +173,7 @@ static zend_class_entry *register_class_IntlRuleBasedBreakIterator(zend_class_en

INIT_CLASS_ENTRY(ce, "IntlRuleBasedBreakIterator", class_IntlRuleBasedBreakIterator_methods);
class_entry = zend_register_internal_class_ex(&ce, class_entry_IntlBreakIterator);
class_entry->ce_flags |= ZEND_ACC_NOT_SERIALIZABLE;

return class_entry;
}
Expand All @@ -182,6 +184,7 @@ static zend_class_entry *register_class_IntlCodePointBreakIterator(zend_class_en

INIT_CLASS_ENTRY(ce, "IntlCodePointBreakIterator", class_IntlCodePointBreakIterator_methods);
class_entry = zend_register_internal_class_ex(&ce, class_entry_IntlBreakIterator);
class_entry->ce_flags |= ZEND_ACC_NOT_SERIALIZABLE;

return class_entry;
}
1 change: 1 addition & 0 deletions ext/intl/breakiterator/breakiterator_iterators.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

/** @generate-class-entries */

/** @not-serializable */
class IntlPartsIterator extends IntlIterator
{
/** @tentative-return-type */
Expand Down
3 changes: 2 additions & 1 deletion ext/intl/breakiterator/breakiterator_iterators_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 267199a0a3532b5acf1d700f14329cdb2f2db0e1 */
* Stub hash: f72f108e37541ac042bb25249ef226211c344189 */

ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(arginfo_class_IntlPartsIterator_getBreakIterator, 0, 0, IntlBreakIterator, 0)
ZEND_END_ARG_INFO()
Expand All @@ -24,6 +24,7 @@ static zend_class_entry *register_class_IntlPartsIterator(zend_class_entry *clas

INIT_CLASS_ENTRY(ce, "IntlPartsIterator", class_IntlPartsIterator_methods);
class_entry = zend_register_internal_class_ex(&ce, class_entry_IntlIterator);
class_entry->ce_flags |= ZEND_ACC_NOT_SERIALIZABLE;

return class_entry;
}
2 changes: 2 additions & 0 deletions ext/intl/calendar/calendar.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

/** @generate-class-entries */

/** @not-serializable */
class IntlCalendar
{
private function __construct() {}
Expand Down Expand Up @@ -281,6 +282,7 @@ public function setTimeZone($timezone): bool {}
public function toDateTime(): DateTime|false {}
}

/** @not-serializable */
class IntlGregorianCalendar extends IntlCalendar
{
/**
Expand Down
4 changes: 3 additions & 1 deletion ext/intl/calendar/calendar_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 7be0e49d2b898587c4bbefaaf613932ae4786c52 */
* Stub hash: 0096dc9e60e2256054d23344e024df1d6527a5fa */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_IntlCalendar___construct, 0, 0, 0)
ZEND_END_ARG_INFO()
Expand Down Expand Up @@ -291,6 +291,7 @@ static zend_class_entry *register_class_IntlCalendar(void)

INIT_CLASS_ENTRY(ce, "IntlCalendar", class_IntlCalendar_methods);
class_entry = zend_register_internal_class_ex(&ce, NULL);
class_entry->ce_flags |= ZEND_ACC_NOT_SERIALIZABLE;

return class_entry;
}
Expand All @@ -301,6 +302,7 @@ static zend_class_entry *register_class_IntlGregorianCalendar(zend_class_entry *

INIT_CLASS_ENTRY(ce, "IntlGregorianCalendar", class_IntlGregorianCalendar_methods);
class_entry = zend_register_internal_class_ex(&ce, class_entry_IntlCalendar);
class_entry->ce_flags |= ZEND_ACC_NOT_SERIALIZABLE;

return class_entry;
}
1 change: 1 addition & 0 deletions ext/intl/collator/collator.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

/** @generate-class-entries */

/** @not-serializable */
class Collator
{
public function __construct(string $locale) {}
Expand Down
3 changes: 2 additions & 1 deletion ext/intl/collator/collator_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 4baf9586ab91f37facc865cf1b3aa6a87e5d732d */
* Stub hash: c2e08f16cdc3d64e82fc277b4a59250d4b19c84e */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Collator___construct, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, locale, IS_STRING, 0)
Expand Down Expand Up @@ -96,6 +96,7 @@ static zend_class_entry *register_class_Collator(void)

INIT_CLASS_ENTRY(ce, "Collator", class_Collator_methods);
class_entry = zend_register_internal_class_ex(&ce, NULL);
class_entry->ce_flags |= ZEND_ACC_NOT_SERIALIZABLE;

return class_entry;
}
1 change: 1 addition & 0 deletions ext/intl/common/common.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

/** @generate-class-entries */

/** @not-serializable */
class IntlIterator implements Iterator
{
/** @tentative-return-type */
Expand Down
Loading