mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Make some exception properties typed
Closes GH-6891
This commit is contained in:
@@ -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 = "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ class a extends exception {
|
||||
$this->message = NULL;
|
||||
$this->string = NULL;
|
||||
$this->code = array();
|
||||
$this->line = "hello";
|
||||
$this->line = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 = "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -22,16 +22,13 @@ interface Throwable extends Stringable
|
||||
|
||||
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 @@ class Exception implements Throwable
|
||||
|
||||
class ErrorException extends Exception
|
||||
{
|
||||
/** @var int */
|
||||
protected $severity = E_ERROR;
|
||||
protected int $severity = E_ERROR;
|
||||
|
||||
public function __construct(
|
||||
string $message = "",
|
||||
@@ -79,16 +75,13 @@ class ErrorException extends Exception
|
||||
|
||||
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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -599,8 +599,7 @@ final class mysqli_warning
|
||||
|
||||
final class mysqli_sql_exception extends RuntimeException
|
||||
{
|
||||
/** @var string */
|
||||
protected $sqlstate = "00000";
|
||||
protected string $sqlstate = "00000";
|
||||
}
|
||||
|
||||
function mysqli_affected_rows(mysqli $mysql): int|string {}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
?>
|
||||
|
||||
@@ -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."");
|
||||
?>
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
?>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
?>
|
||||
|
||||
@@ -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 ]
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user