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
15 changes: 15 additions & 0 deletions php_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,19 @@ zend_array_to_list(HashTable *arr)
}
#endif

/* From PHP 8.1 on, the generated arginfo flags our classes with
* ZEND_ACC_NOT_SERIALIZABLE; before, handlers deny (un)serialization */
#if PHP_VERSION_ID < 80100
#include <zend_interfaces.h>
#endif

static zend_always_inline void
redis_class_deny_serialization(zend_class_entry *ce)
{
#if PHP_VERSION_ID < 80100
ce->serialize = zend_class_serialize_deny;
ce->unserialize = zend_class_unserialize_deny;
#endif
}

#endif // PHP_REDIS_COMPAT_H
1 change: 1 addition & 0 deletions redis.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ PHP_MINIT_FUNCTION(redis)
/* Redis class */
redis_ce = register_class_Redis();
redis_ce->create_object = create_redis_object;
redis_class_deny_serialization(redis_ce);

/* Redis object handler initialization */
redis_init_object_handlers();
Expand Down
1 change: 1 addition & 0 deletions redis.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @generate-class-entries
*/

/** @not-serializable */
class Redis {
/**
* Returned by `\Redis::type()` when the key does not exist or has a type
Expand Down
7 changes: 5 additions & 2 deletions redis_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: b3c1c6723fea03ccd447f71a5d18a31279e482c2 */
* Stub hash: fbc9315c36f7f6c38d2d057338ea41ded89a1c6d */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct, 0, 0, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 1, "null")
Expand Down Expand Up @@ -1974,9 +1974,12 @@ static zend_class_entry *register_class_Redis(void)

INIT_CLASS_ENTRY(ce, "Redis", class_Redis_methods);
#if (PHP_VERSION_ID >= 80400)
class_entry = zend_register_internal_class_with_flags(&ce, NULL, 0);
class_entry = zend_register_internal_class_with_flags(&ce, NULL, ZEND_ACC_NOT_SERIALIZABLE);
#else
class_entry = zend_register_internal_class_ex(&ce, NULL);
#if (PHP_VERSION_ID >= 80100)
class_entry->ce_flags |= ZEND_ACC_NOT_SERIALIZABLE;
#endif
#endif

zval const_REDIS_NOT_FOUND_value;
Expand Down
1 change: 1 addition & 0 deletions redis_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ PHP_MINIT_FUNCTION(redis_array)
/* RedisArray class */
redis_array_ce = register_class_RedisArray();
redis_array_ce->create_object = create_redis_array_object;
redis_class_deny_serialization(redis_array_ce);

/* RedisArray object handler initialization */
redis_array_init_object_handlers();
Expand Down
2 changes: 2 additions & 0 deletions redis_array.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@
* @method RedisArray|array|false zunion(array $keys, ?array $weights = null, ?array $options = null)
* @method RedisArray|int|false zunionstore(string $dst, array $keys, ?array $weights = null, ?string $aggregate = null)
* @method RedisArray|string|false digest(string $key)
*
* @not-serializable
*/
class RedisArray {

Expand Down
7 changes: 5 additions & 2 deletions redis_array_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: 1293a0ccef1e700da87d9ace76c3a05d91c0ffc7 */
* Stub hash: 50774f3658dcf5ba095a2a2965d109f9f822e88f */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_RedisArray___call, 0, 2, IS_MIXED, 0)
ZEND_ARG_TYPE_INFO(0, function_name, IS_STRING, 0)
Expand Down Expand Up @@ -182,9 +182,12 @@ static zend_class_entry *register_class_RedisArray(void)

INIT_CLASS_ENTRY(ce, "RedisArray", class_RedisArray_methods);
#if (PHP_VERSION_ID >= 80400)
class_entry = zend_register_internal_class_with_flags(&ce, NULL, 0);
class_entry = zend_register_internal_class_with_flags(&ce, NULL, ZEND_ACC_NOT_SERIALIZABLE);
#else
class_entry = zend_register_internal_class_ex(&ce, NULL);
#if (PHP_VERSION_ID >= 80100)
class_entry->ce_flags |= ZEND_ACC_NOT_SERIALIZABLE;
#endif
#endif

return class_entry;
Expand Down
2 changes: 1 addition & 1 deletion redis_array_legacy_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: 1293a0ccef1e700da87d9ace76c3a05d91c0ffc7 */
* Stub hash: 50774f3658dcf5ba095a2a2965d109f9f822e88f */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisArray___call, 0, 0, 2)
ZEND_ARG_INFO(0, function_name)
Expand Down
1 change: 1 addition & 0 deletions redis_cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ PHP_MINIT_FUNCTION(redis_cluster)
{
redis_cluster_ce = register_class_RedisCluster();
redis_cluster_ce->create_object = create_cluster_context;
redis_class_deny_serialization(redis_cluster_ce);

redis_cluster_exception_ce = register_class_RedisClusterException(spl_ce_RuntimeException);

Expand Down
1 change: 1 addition & 0 deletions redis_cluster.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @generate-class-entries
*/

/** @not-serializable */
class RedisCluster {
/**
* Used to configure how `PhpRedis` will fail over to replica nodes when a
Expand Down
7 changes: 5 additions & 2 deletions redis_cluster_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: 097f539fffdd7fbfd13b82b501badc3009568757 */
* Stub hash: 82a77e4ed63d38d7e361fc1c016bfbe5f8a0df31 */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster___construct, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 1)
Expand Down Expand Up @@ -1797,9 +1797,12 @@ static zend_class_entry *register_class_RedisCluster(void)

INIT_CLASS_ENTRY(ce, "RedisCluster", class_RedisCluster_methods);
#if (PHP_VERSION_ID >= 80400)
class_entry = zend_register_internal_class_with_flags(&ce, NULL, 0);
class_entry = zend_register_internal_class_with_flags(&ce, NULL, ZEND_ACC_NOT_SERIALIZABLE);
#else
class_entry = zend_register_internal_class_ex(&ce, NULL);
#if (PHP_VERSION_ID >= 80100)
class_entry->ce_flags |= ZEND_ACC_NOT_SERIALIZABLE;
#endif
#endif

zval const_OPT_SLAVE_FAILOVER_value;
Expand Down
2 changes: 1 addition & 1 deletion redis_cluster_legacy_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: 097f539fffdd7fbfd13b82b501badc3009568757 */
* Stub hash: 82a77e4ed63d38d7e361fc1c016bfbe5f8a0df31 */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster___construct, 0, 0, 1)
ZEND_ARG_INFO(0, name)
Expand Down
2 changes: 1 addition & 1 deletion redis_legacy_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: b3c1c6723fea03ccd447f71a5d18a31279e482c2 */
* Stub hash: fbc9315c36f7f6c38d2d057338ea41ded89a1c6d */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct, 0, 0, 0)
ZEND_ARG_INFO(0, options)
Expand Down
1 change: 1 addition & 0 deletions redis_sentinel.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ PHP_MINIT_FUNCTION(redis_sentinel)
/* RedisSentinel class */
redis_sentinel_ce = register_class_RedisSentinel();
redis_sentinel_ce->create_object = create_sentinel_object;
redis_class_deny_serialization(redis_sentinel_ce);

/* RedisSentinel object handler initialization */
redis_sentinel_init_object_handlers();
Expand Down
1 change: 1 addition & 0 deletions redis_sentinel.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @generate-class-entries
*/

/** @not-serializable */
class RedisSentinel {

public function __construct(?array $options = null);
Expand Down
7 changes: 5 additions & 2 deletions redis_sentinel_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: ca40579af888c5bb0661cd0201d840297474479a */
* Stub hash: 5b7b25a02bdb32016fb94ca6029dc0d871f32996 */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisSentinel___construct, 0, 0, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 1, "null")
Expand Down Expand Up @@ -68,9 +68,12 @@ static zend_class_entry *register_class_RedisSentinel(void)

INIT_CLASS_ENTRY(ce, "RedisSentinel", class_RedisSentinel_methods);
#if (PHP_VERSION_ID >= 80400)
class_entry = zend_register_internal_class_with_flags(&ce, NULL, 0);
class_entry = zend_register_internal_class_with_flags(&ce, NULL, ZEND_ACC_NOT_SERIALIZABLE);
#else
class_entry = zend_register_internal_class_ex(&ce, NULL);
#if (PHP_VERSION_ID >= 80100)
class_entry->ce_flags |= ZEND_ACC_NOT_SERIALIZABLE;
#endif
#endif

return class_entry;
Expand Down
2 changes: 1 addition & 1 deletion redis_sentinel_legacy_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: ca40579af888c5bb0661cd0201d840297474479a */
* Stub hash: 5b7b25a02bdb32016fb94ca6029dc0d871f32996 */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisSentinel___construct, 0, 0, 0)
ZEND_ARG_INFO(0, options)
Expand Down
15 changes: 15 additions & 0 deletions tests/RedisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9468,5 +9468,20 @@ public function testAnonymousClassSerializationFailure() {
$this->assertTrue($this->redis->set('after_failure', 'ok'));
$this->assertEquals('ok', $this->redis->get('after_failure'));
}

public function testNotSerializable() {
$this->assertThrowsMatch($this->redis, function ($redis) {
serialize($redis);
}, "/^Serialization of '" . get_class($this->redis) . "' is not allowed$/");

/* Before PHP 8.1, only the C: format reaches the handler that throws */
$format = PHP_VERSION_ID < 80100 ? 'C' : 'O';

foreach (['Redis', 'RedisArray', 'RedisCluster', 'RedisSentinel'] as $class) {
$this->assertThrowsMatch($class, function ($class) use ($format) {
unserialize($format . ':' . strlen($class) . ':"' . $class . '":0:{}');
}, "/^Unserialization of '$class' is not allowed$/");
}
}
}
?>
Loading