Skip to content

Commit 6e4b202

Browse files
committed
Switch PDO to use serialize_deny
And remove dummy __sleep/__wakeup. This switches the thrown exception type from PDOException to Exception.
1 parent a624c2b commit 6e4b202

File tree

4 files changed

+9
-21
lines changed

4 files changed

+9
-21
lines changed

UPGRADING

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ PHP 7.4 UPGRADE NOTES
3131
. The default parameter value of idn_to_ascii() and idn_to_utf8() is now
3232
INTL_IDNA_VARIANT_UTS46 instead of the deprecated INTL_IDNA_VARIANT_2003.
3333

34+
- PDO:
35+
. Attempting to serialize a PDO instance will now generate an Exception
36+
rather than a PDOException, consistent with other internal classes which
37+
do not support serialization.
38+
3439
- Reflection:
3540
. Reflection objects will now generate an exception if an attempt is made
3641
to serialize them. Serialization for reflection objects was never

ext/pdo/pdo_dbh.c

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "zend_exceptions.h"
3434
#include "zend_object_handlers.h"
3535
#include "zend_hash.h"
36+
#include "zend_interfaces.h"
3637

3738
static int pdo_dbh_attribute_set(pdo_dbh_t *dbh, zend_long attr, zval *value);
3839

@@ -1153,22 +1154,6 @@ static PHP_METHOD(PDO, quote)
11531154
}
11541155
/* }}} */
11551156

1156-
/* {{{ proto PDO::__wakeup()
1157-
Prevents use of a PDO instance that has been unserialized */
1158-
static PHP_METHOD(PDO, __wakeup)
1159-
{
1160-
zend_throw_exception_ex(php_pdo_get_exception(), 0, "You cannot serialize or unserialize PDO instances");
1161-
}
1162-
/* }}} */
1163-
1164-
/* {{{ proto int PDO::__sleep()
1165-
Prevents serialization of a PDO instance */
1166-
static PHP_METHOD(PDO, __sleep)
1167-
{
1168-
zend_throw_exception_ex(php_pdo_get_exception(), 0, "You cannot serialize or unserialize PDO instances");
1169-
}
1170-
/* }}} */
1171-
11721157
/* {{{ proto array PDO::getAvailableDrivers()
11731158
Return array of available PDO drivers */
11741159
static PHP_METHOD(PDO, getAvailableDrivers)
@@ -1241,8 +1226,6 @@ const zend_function_entry pdo_dbh_functions[] = /* {{{ */ {
12411226
PHP_ME(PDO, errorInfo, arginfo_pdo__void, ZEND_ACC_PUBLIC)
12421227
PHP_ME(PDO, getAttribute, arginfo_pdo_getattribute, ZEND_ACC_PUBLIC)
12431228
PHP_ME(PDO, quote, arginfo_pdo_quote, ZEND_ACC_PUBLIC)
1244-
PHP_ME(PDO, __wakeup, arginfo_pdo__void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
1245-
PHP_ME(PDO, __sleep, arginfo_pdo__void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
12461229
PHP_ME(PDO, getAvailableDrivers, arginfo_pdo__void, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
12471230
PHP_FE_END
12481231
};
@@ -1384,6 +1367,8 @@ void pdo_dbh_init(void)
13841367
INIT_CLASS_ENTRY(ce, "PDO", pdo_dbh_functions);
13851368
pdo_dbh_ce = zend_register_internal_class(&ce);
13861369
pdo_dbh_ce->create_object = pdo_dbh_new;
1370+
pdo_dbh_ce->serialize = zend_class_serialize_deny;
1371+
pdo_dbh_ce->unserialize = zend_class_unserialize_deny;
13871372

13881373
memcpy(&pdo_dbh_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
13891374
pdo_dbh_object_handlers.offset = XtOffsetOf(pdo_dbh_object_t, std);

ext/pdo/tests/pecl_bug_5217.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ try {
2525
echo "PHP Didn't crash!\n";
2626
?>
2727
--EXPECT--
28-
Safely caught You cannot serialize or unserialize PDO instances
28+
Safely caught Serialization of 'PDO' is not allowed
2929
PHP Didn't crash!

ext/pdo_mysql/tests/pdo_mysql_interface.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ if (false == MySQLPDOTest::detect_transactional_mysql_engine($db))
2929
'getAttribute' => true,
3030
'quote' => true,
3131
'inTransaction' => true,
32-
'__wakeup' => true,
33-
'__sleep' => true,
3432
'getAvailableDrivers' => true,
3533
);
3634
$classname = get_class($db);

0 commit comments

Comments
 (0)