[php-src] master: Make some exception properties typed
| From: | Máté Kocsis | Date: | Thu, 22 Apr 2021 08:24:21 +0000 |
| Subject: | [php-src] master: Make some exception properties typed | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-115749@lists.php.net to get a copy of this message | ||
Author: Máté Kocsis (kocsismate)
Date: 2021-04-22T10:22:50+02:00
Commit: https://github.com/php/php-src/commit/30a082cb1673cf8406daa025a67b744916a95214
Raw diff: https://github.com/php/php-src/commit/30a082cb1673cf8406daa025a67b744916a95214.diff
Make some exception properties typed
Closes GH-6891
Changed paths:
M Zend/tests/bug50005.phpt
M Zend/tests/bug64821.1.phpt
M Zend/tests/bug64821.2.phpt
M Zend/tests/bug64821.3.phpt
M Zend/zend_exceptions.c
M Zend/zend_exceptions.stub.php
M Zend/zend_exceptions_arginfo.h
M ext/mysqli/mysqli.stub.php
M ext/mysqli/mysqli_arginfo.h
M ext/soap/tests/bug73452.phpt
M ext/standard/tests/serialize/bug69793.phpt
M ext/standard/tests/serialize/bug72663_2.phpt
M ext/standard/tests/serialize/bug72663_3.phpt
M ext/standard/tests/strings/bug72663.phpt
M ext/standard/tests/strings/bug72663_2.phpt
M sapi/cli/tests/005.phpt
M tests/lang/038.phpt
Diff:
diff --git a/Zend/tests/bug50005.phpt b/Zend/tests/bug50005.phpt
index 8b3817cd5f292..a82a84f7054bd 100644
--- a/Zend/tests/bug50005.phpt
+++ b/Zend/tests/bug50005.phpt
@@ -5,7 +5,7 @@ Bug #50005 (Throwing through Reflection modified Exception object makes segmenta
class a extends exception {
public function __construct() {
- $this->file = null;
+ $this->file = "";
}
}
diff --git a/Zend/tests/bug64821.1.phpt b/Zend/tests/bug64821.1.phpt
index 52713e2211c54..2a1a92f715fab 100644
--- a/Zend/tests/bug64821.1.phpt
+++ b/Zend/tests/bug64821.1.phpt
@@ -8,7 +8,7 @@ class a extends exception {
$this->message = NULL;
$this->string = NULL;
$this->code = array();
- $this->line = "hello";
+ $this->line = 0;
}
}
diff --git a/Zend/tests/bug64821.2.phpt b/Zend/tests/bug64821.2.phpt
index cac0a948f9be3..61b17ff6da781 100644
--- a/Zend/tests/bug64821.2.phpt
+++ b/Zend/tests/bug64821.2.phpt
@@ -5,7 +5,7 @@ Bug #64821 Custom Exceptions crash when internal properties overridden (variatio
class a extends exception {
public function __construct() {
- $this->line = array();
+ $this->line = 0;
}
}
diff --git a/Zend/tests/bug64821.3.phpt b/Zend/tests/bug64821.3.phpt
index d94f1ba361edf..d1f1ec9a51657 100644
--- a/Zend/tests/bug64821.3.phpt
+++ b/Zend/tests/bug64821.3.phpt
@@ -5,8 +5,8 @@ Bug #64821 Custom Exceptions crash when internal properties overridden (variatio
class a extends exception {
public function __construct() {
- $this->line = array();
- $this->file = NULL;
+ $this->line = 0;
+ $this->file = "";
}
}
diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c
index 61a0aa923dda9..add3bb50a4c2a 100644
--- a/Zend/zend_exceptions.c
+++ b/Zend/zend_exceptions.c
@@ -757,8 +757,11 @@ void zend_register_default_exception(void) /* {{{ */
zend_ce_error_exception = register_class_ErrorException(zend_ce_exception);
zend_ce_error_exception->create_object = zend_error_exception_new;
+
/* Declared manually because it uses constant E_ERROR. */
- zend_declare_property_long(zend_ce_error_exception, "severity",
sizeof("severity")-1, E_ERROR, ZEND_ACC_PROTECTED);
+ zval severity_default_value;
+ ZVAL_LONG(&severity_default_value, E_ERROR);
+ zend_declare_typed_property(zend_ce_error_exception, ZSTR_KNOWN(ZEND_STR_SEVERITY),
&severity_default_value, ZEND_ACC_PROTECTED, NULL, (zend_type)
ZEND_TYPE_INIT_MASK(MAY_BE_LONG));
zend_ce_error = register_class_Error(zend_ce_throwable);
zend_ce_error->create_object = zend_default_exception_new;
diff --git a/Zend/zend_exceptions.stub.php b/Zend/zend_exceptions.stub.php
index ece019bbb9c7e..be00b6b65dbea 100644
--- a/Zend/zend_exceptions.stub.php
+++ b/Zend/zend_exceptions.stub.php
@@ -22,16 +22,13 @@ public function getTraceAsString(): string;
class Exception implements Throwable
{
- /** @var string */
+ /** @var string Intentionally left untyped for BC reasons */
protected $message = "";
- /** @var string */
- private $string = "";
- /** @var int */
+ private string $string = "";
+ /** @var int Intentionally left untyped for BC reasons */
protected $code = 0;
- /** @var string|null */
- protected $file = null;
- /** @var int|null */
- protected $line = null;
+ protected string $file = "";
+ protected int $line = 0;
private array $trace = [];
private ?Throwable $previous = null;
@@ -62,8 +59,7 @@ public function __toString(): string {}
class ErrorException extends Exception
{
- /** @var int */
- protected $severity = E_ERROR;
+ protected int $severity = E_ERROR;
public function __construct(
string $message = "",
@@ -79,16 +75,13 @@ final public function getSeverity(): int {}
class Error implements Throwable
{
- /** @var string */
+ /** @var string Intentionally left untyped for BC reasons */
protected $message = "";
- /** @var string */
- private $string = "";
- /** @var int */
+ private string $string = "";
+ /** @var int Intentionally left untyped for BC reasons */
protected $code = 0;
- /** @var string|null */
- protected $file = null;
- /** @var int|null */
- protected $line = null;
+ protected string $file = "";
+ protected int $line;
private array $trace = [];
private ?Throwable $previous = null;
diff --git a/Zend/zend_exceptions_arginfo.h b/Zend/zend_exceptions_arginfo.h
index fd92ff0635535..4779d698e1980 100644
--- a/Zend/zend_exceptions_arginfo.h
+++ b/Zend/zend_exceptions_arginfo.h
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
- * Stub hash: ef8c275a543d67fd96a775b0b18098ccdb428285 */
+ * Stub hash: 9a9ce2975a7449a621d364beca646525fc56b294 */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Throwable_getMessage, 0, 0, IS_STRING, 0)
ZEND_END_ARG_INFO()
@@ -214,7 +214,7 @@ static zend_class_entry *register_class_Exception(zend_class_entry *class_entry_
zval property_string_default_value;
ZVAL_EMPTY_STRING(&property_string_default_value);
zend_string *property_string_name = zend_string_init("string",
sizeof("string") - 1, 1);
- zend_declare_property_ex(class_entry, property_string_name, &property_string_default_value,
ZEND_ACC_PRIVATE, NULL);
+ zend_declare_typed_property(class_entry, property_string_name, &property_string_default_value,
ZEND_ACC_PRIVATE, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING));
zend_string_release(property_string_name);
zval property_code_default_value;
@@ -224,15 +224,15 @@ static zend_class_entry *register_class_Exception(zend_class_entry
*class_entry_
zend_string_release(property_code_name);
zval property_file_default_value;
- ZVAL_NULL(&property_file_default_value);
+ ZVAL_EMPTY_STRING(&property_file_default_value);
zend_string *property_file_name = zend_string_init("file", sizeof("file") - 1,
1);
- zend_declare_property_ex(class_entry, property_file_name, &property_file_default_value,
ZEND_ACC_PROTECTED, NULL);
+ zend_declare_typed_property(class_entry, property_file_name, &property_file_default_value,
ZEND_ACC_PROTECTED, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING));
zend_string_release(property_file_name);
zval property_line_default_value;
- ZVAL_NULL(&property_line_default_value);
+ ZVAL_LONG(&property_line_default_value, 0);
zend_string *property_line_name = zend_string_init("line", sizeof("line") - 1,
1);
- zend_declare_property_ex(class_entry, property_line_name, &property_line_default_value,
ZEND_ACC_PROTECTED, NULL);
+ zend_declare_typed_property(class_entry, property_line_name, &property_line_default_value,
ZEND_ACC_PROTECTED, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG));
zend_string_release(property_line_name);
zval property_trace_default_value;
@@ -278,7 +278,7 @@ static zend_class_entry *register_class_Error(zend_class_entry *class_entry_Thro
zval property_string_default_value;
ZVAL_EMPTY_STRING(&property_string_default_value);
zend_string *property_string_name = zend_string_init("string",
sizeof("string") - 1, 1);
- zend_declare_property_ex(class_entry, property_string_name, &property_string_default_value,
ZEND_ACC_PRIVATE, NULL);
+ zend_declare_typed_property(class_entry, property_string_name, &property_string_default_value,
ZEND_ACC_PRIVATE, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING));
zend_string_release(property_string_name);
zval property_code_default_value;
@@ -288,15 +288,15 @@ static zend_class_entry *register_class_Error(zend_class_entry
*class_entry_Thro
zend_string_release(property_code_name);
zval property_file_default_value;
- ZVAL_NULL(&property_file_default_value);
+ ZVAL_EMPTY_STRING(&property_file_default_value);
zend_string *property_file_name = zend_string_init("file", sizeof("file") - 1,
1);
- zend_declare_property_ex(class_entry, property_file_name, &property_file_default_value,
ZEND_ACC_PROTECTED, NULL);
+ zend_declare_typed_property(class_entry, property_file_name, &property_file_default_value,
ZEND_ACC_PROTECTED, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING));
zend_string_release(property_file_name);
zval property_line_default_value;
- ZVAL_NULL(&property_line_default_value);
+ ZVAL_UNDEF(&property_line_default_value);
zend_string *property_line_name = zend_string_init("line", sizeof("line") - 1,
1);
- zend_declare_property_ex(class_entry, property_line_name, &property_line_default_value,
ZEND_ACC_PROTECTED, NULL);
+ zend_declare_typed_property(class_entry, property_line_name, &property_line_default_value,
ZEND_ACC_PROTECTED, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG));
zend_string_release(property_line_name);
zval property_trace_default_value;
diff --git a/ext/mysqli/mysqli.stub.php b/ext/mysqli/mysqli.stub.php
index 56673b3b54bfe..99ce77dc4e640 100644
--- a/ext/mysqli/mysqli.stub.php
+++ b/ext/mysqli/mysqli.stub.php
@@ -599,8 +599,7 @@ public function next(): bool {}
final class mysqli_sql_exception extends RuntimeException
{
- /** @var string */
- protected $sqlstate = "00000";
+ protected string $sqlstate = "00000";
}
function mysqli_affected_rows(mysqli $mysql): int|string {}
diff --git a/ext/mysqli/mysqli_arginfo.h b/ext/mysqli/mysqli_arginfo.h
index 23e14cd39b77b..fe4504825270d 100644
--- a/ext/mysqli/mysqli_arginfo.h
+++ b/ext/mysqli/mysqli_arginfo.h
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
- * Stub hash: 14c5c4960e70f5b38fc6c4f4403804cc28147b0b */
+ * Stub hash: b0232d18f570208d673ad7535ca60997e038acb8 */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mysqli_affected_rows, 0, 1,
MAY_BE_LONG|MAY_BE_STRING)
ZEND_ARG_OBJ_INFO(0, mysql, mysqli, 0)
@@ -1356,7 +1356,7 @@ static zend_class_entry *register_class_mysqli_sql_exception(zend_class_entry
*c
zend_string *property_sqlstate_default_value_str = zend_string_init("00000",
sizeof("00000") - 1, 1);
ZVAL_STR(&property_sqlstate_default_value, property_sqlstate_default_value_str);
zend_string *property_sqlstate_name = zend_string_init("sqlstate",
sizeof("sqlstate") - 1, 1);
- zend_declare_property_ex(class_entry, property_sqlstate_name,
&property_sqlstate_default_value, ZEND_ACC_PROTECTED, NULL);
+ zend_declare_typed_property(class_entry, property_sqlstate_name,
&property_sqlstate_default_value, ZEND_ACC_PROTECTED, NULL, (zend_type)
ZEND_TYPE_INIT_MASK(MAY_BE_STRING));
zend_string_release(property_sqlstate_name);
return class_entry;
diff --git a/ext/soap/tests/bug73452.phpt b/ext/soap/tests/bug73452.phpt
index 57a5786a3f377..22b8aafdf36aa 100644
--- a/ext/soap/tests/bug73452.phpt
+++ b/ext/soap/tests/bug73452.phpt
@@ -5,7 +5,7 @@ soap
--FILE--
<?php
-$data =
'O:9:"SoapFault":4:{s:9:"faultcode";i:4298448493;s:11:"faultstring";i:4298448543;s:7:"'."\0*\0".'file";i:4298447319;s:7:"'."\0*\0".'line";s:4:"ryat";}';
+$data =
'O:9:"SoapFault":4:{s:9:"faultcode";i:4298448493;s:11:"faultstring";i:4298448543;s:7:"'."\0*\0".'file";s:0:"";s:7:"'."\0*\0".'line";i:0;}';
echo unserialize($data);
?>
diff --git a/ext/standard/tests/serialize/bug69793.phpt b/ext/standard/tests/serialize/bug69793.phpt
index 6c2d1df026256..1ebc831a9adf4 100644
--- a/ext/standard/tests/serialize/bug69793.phpt
+++ b/ext/standard/tests/serialize/bug69793.phpt
@@ -2,7 +2,7 @@
Bug #69793: Remotely triggerable stack exhaustion via recursive method calls
--FILE--
<?php
-$e =
unserialize('O:9:"Exception":7:{s:17:"'."\0".'Exception'."\0".'string";s:1:"a";s:7:"'."\0".'*'."\0".'code";i:0;s:7:"'."\0".'*'."\0".'file";R:1;s:7:"'."\0".'*'."\0".'line";i:1337;s:16:"'."\0".'Exception'."\0".'trace";a:0:{}s:19:"'."\0".'Exception'."\0".'previous";i:10;s:10:"'."\0".'*'."\0".'message";N;}');
+$e =
unserialize('O:9:"Exception":7:{s:17:"'."\0".'Exception'."\0".'string";s:1:"a";s:7:"'."\0".'*'."\0".'code";i:0;s:7:"'."\0".'*'."\0".'file";s:0:"";s:7:"'."\0".'*'."\0".'line";i:1337;s:16:"'."\0".'Exception'."\0".'trace";a:0:{}s:19:"'."\0".'Exception'."\0".'previous";i:10;s:10:"'."\0".'*'."\0".'message";N;}');
var_dump($e."");
?>
diff --git a/ext/standard/tests/serialize/bug72663_2.phpt
b/ext/standard/tests/serialize/bug72663_2.phpt
index 8825dc5efc3f5..2d7fa772ec451 100644
--- a/ext/standard/tests/serialize/bug72663_2.phpt
+++ b/ext/standard/tests/serialize/bug72663_2.phpt
@@ -13,7 +13,7 @@ class obj implements Serializable {
}
}
-$inner =
'a:1:{i:0;O:9:"Exception":2:{s:7:"'."\0".'*'."\0".'file";R:4;}';
+$inner =
'a:1:{i:0;O:9:"Exception":2:{s:7:"'."\0".'*'."\0".'file";s:0:"";}';
$exploit =
'a:2:{i:0;C:3:"obj":'.strlen($inner).':{'.$inner.'}i:1;R:4;}';
var_dump(unserialize($exploit));
@@ -21,7 +21,7 @@ var_dump(unserialize($exploit));
--EXPECTF--
Notice: unserialize(): Unexpected end of serialized data in %s on line %d
-Notice: unserialize(): Error at offset 46 of 47 bytes in %s on line %d
+Notice: unserialize(): Error at offset 49 of 50 bytes in %s on line %d
-Notice: unserialize(): Error at offset 79 of 80 bytes in %s on line %d
+Notice: unserialize(): Error at offset 82 of 83 bytes in %s on line %d
bool(false)
diff --git a/ext/standard/tests/serialize/bug72663_3.phpt
b/ext/standard/tests/serialize/bug72663_3.phpt
index 706bdf21fb9ab..c3051a685d85e 100644
--- a/ext/standard/tests/serialize/bug72663_3.phpt
+++ b/ext/standard/tests/serialize/bug72663_3.phpt
@@ -7,7 +7,7 @@ session.serialize_handler=php_serialize
--FILE--
<?php
session_start();
-$sess =
'O:9:"Exception":2:{s:7:"'."\0".'*'."\0".'file";R:1;}';
+$sess =
'O:9:"Exception":2:{s:7:"'."\0".'*'."\0".'file";s:0:"";}';
session_decode($sess);
var_dump($_SESSION);
?>
diff --git a/ext/standard/tests/strings/bug72663.phpt b/ext/standard/tests/strings/bug72663.phpt
index c9abd51b0803b..384ab595bf240 100644
--- a/ext/standard/tests/strings/bug72663.phpt
+++ b/ext/standard/tests/strings/bug72663.phpt
@@ -12,7 +12,7 @@ class obj implements Serializable {
}
}
-$inner =
'a:1:{i:0;O:9:"Exception":2:{s:7:"'."\0".'*'."\0".'file";R:4;}';
+$inner =
'a:1:{i:0;O:9:"Exception":2:{s:7:"'."\0".'*'."\0".'file";s:0:"";}';
$exploit =
'a:2:{i:0;C:3:"obj":'.strlen($inner).':{'.$inner.'}i:1;R:4;}';
var_dump(unserialize($exploit));
@@ -21,8 +21,8 @@ DONE
--EXPECTF--
Notice: unserialize(): Unexpected end of serialized data in %sbug72663.php on line %d
-Notice: unserialize(): Error at offset 46 of 47 bytes in %sbug72663.php on line %d
+Notice: unserialize(): Error at offset 49 of 50 bytes in %sbug72663.php on line %d
-Notice: unserialize(): Error at offset 79 of 80 bytes in %sbug72663.php on line %d
+Notice: unserialize(): Error at offset 82 of 83 bytes in %sbug72663.php on line %d
bool(false)
DONE
diff --git a/ext/standard/tests/strings/bug72663_2.phpt b/ext/standard/tests/strings/bug72663_2.phpt
index d0d7f81008597..6d626e0175470 100644
--- a/ext/standard/tests/strings/bug72663_2.phpt
+++ b/ext/standard/tests/strings/bug72663_2.phpt
@@ -11,7 +11,7 @@ if (!extension_loaded("session")) {
ini_set('session.serialize_handler', 'php_serialize');
session_start();
-$sess =
'O:9:"Exception":2:{s:7:"'."\0".'*'."\0".'file";R:1;}';
+$sess =
'O:9:"Exception":2:{s:7:"'."\0".'*'."\0".'file";s:0:"";}';
session_decode($sess);
var_dump($_SESSION);
?>
diff --git a/sapi/cli/tests/005.phpt b/sapi/cli/tests/005.phpt
index de2ca28a1fec0..be4fff528cc9a 100644
--- a/sapi/cli/tests/005.phpt
+++ b/sapi/cli/tests/005.phpt
@@ -37,7 +37,7 @@ string(183) "Class [ <internal:Core> class stdClass ] {
}
"
-string(2188) "Class [ <internal:Core> class Exception implements Throwable, Stringable ]
{
+string(2201) "Class [ <internal:Core> class Exception implements Throwable, Stringable ]
{
- Constants [0] {
}
@@ -50,10 +50,10 @@ string(2188) "Class [ <internal:Core> class Exception implements
Throwable, Stri
- Properties [7] {
Property [ protected $message = '' ]
- Property [ private $string = '' ]
+ Property [ private string $string = '' ]
Property [ protected $code = 0 ]
- Property [ protected $file = NULL ]
- Property [ protected $line = NULL ]
+ Property [ protected string $file = '' ]
+ Property [ protected int $line = 0 ]
Property [ private array $trace = Array ]
Property [ private ?Throwable $previous = NULL ]
}
diff --git a/tests/lang/038.phpt b/tests/lang/038.phpt
index 677c11be9c80f..915969f366231 100644
--- a/tests/lang/038.phpt
+++ b/tests/lang/038.phpt
@@ -5,7 +5,7 @@ Convert warnings to exceptions
class MyException extends Exception
{
- function __construct($errstr, $errno=0, $errfile='', $errline='')
+ function __construct($errstr, $errno=0, $errfile='', $errline=0)
{
parent::__construct($errstr, $errno);
$this->file = $errfile;