Sitelet https://github.com/phpredis/phpredis/commit/3675f442
Skip to content

Commit 3675f44

Browse files
committed
mark auth param as sensitive for PHP 8.2
refactor MINIT (split in each class sources file) use @generate-class-entries in stub files add RedisException and RedisClusterException in stub files
1 parent 0f1ca0c commit 3675f44

20 files changed

Lines changed: 208 additions & 59 deletions

‎library.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
#define REDIS_VALUE_EXCEPTION(m) zend_value_error(m)
3636
#endif
3737

38+
#if PHP_VERSION_ID < 80200
39+
#define zend_mark_function_parameter_as_sensitive(a,b,c)
40+
#endif
3841

3942
void redis_register_persistent_resource(zend_string *id, void *ptr, int le_id);
4043
void free_reply_callbacks(RedisSock *redis_sock);

‎redis.c‎

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,13 @@ extern ps_module ps_mod_redis;
5252
extern ps_module ps_mod_redis_cluster;
5353
#endif
5454

55-
extern zend_class_entry *redis_array_ce;
56-
extern zend_class_entry *redis_cluster_ce;
57-
extern zend_class_entry *redis_cluster_exception_ce;
58-
extern zend_class_entry *redis_sentinel_ce;
59-
6055
zend_class_entry *redis_ce;
6156
zend_class_entry *redis_exception_ce;
6257

6358
#if PHP_VERSION_ID < 80000
6459
#include "redis_legacy_arginfo.h"
6560
#else
61+
#include "zend_attributes.h"
6662
#include "redis_arginfo.h"
6763
#endif
6864

@@ -440,14 +436,6 @@ static PHP_GINIT_FUNCTION(redis)
440436
PHP_MINIT_FUNCTION(redis)
441437
{
442438
struct timeval tv;
443-
444-
zend_class_entry redis_class_entry;
445-
zend_class_entry redis_array_class_entry;
446-
zend_class_entry redis_cluster_class_entry;
447-
zend_class_entry redis_sentinel_class_entry;
448-
zend_class_entry redis_exception_class_entry;
449-
zend_class_entry redis_cluster_exception_class_entry;
450-
451439
zend_class_entry *exception_ce = NULL;
452440

453441
/* Seed random generator (for RedisCluster failover) */
@@ -457,24 +445,17 @@ PHP_MINIT_FUNCTION(redis)
457445
REGISTER_INI_ENTRIES();
458446

459447
/* Redis class */
460-
INIT_CLASS_ENTRY(redis_class_entry, "Redis", redis_get_methods());
461-
redis_ce = zend_register_internal_class(&redis_class_entry);
448+
redis_ce = register_class_Redis();
462449
redis_ce->create_object = create_redis_object;
463450

464451
/* RedisArray class */
465-
INIT_CLASS_ENTRY(redis_array_class_entry, "RedisArray", redis_array_get_methods());
466-
redis_array_ce = zend_register_internal_class(&redis_array_class_entry);
467-
redis_array_ce->create_object = create_redis_array_object;
452+
ZEND_MINIT(redis_array)(INIT_FUNC_ARGS_PASSTHRU);
468453

469454
/* RedisCluster class */
470-
INIT_CLASS_ENTRY(redis_cluster_class_entry, "RedisCluster", redis_cluster_get_methods());
471-
redis_cluster_ce = zend_register_internal_class(&redis_cluster_class_entry);
472-
redis_cluster_ce->create_object = create_cluster_context;
455+
ZEND_MINIT(redis_cluster)(INIT_FUNC_ARGS_PASSTHRU);
473456

474457
/* RedisSentinel class */
475-
INIT_CLASS_ENTRY(redis_sentinel_class_entry, "RedisSentinel", redis_sentinel_get_methods());
476-
redis_sentinel_ce = zend_register_internal_class(&redis_sentinel_class_entry);
477-
redis_sentinel_ce->create_object = create_sentinel_object;
458+
ZEND_MINIT(redis_sentinel)(INIT_FUNC_ARGS_PASSTHRU);
478459

479460
/* Register our cluster cache list item */
480461
le_cluster_slot_cache = zend_register_list_destructors_ex(NULL, cluster_cache_dtor,
@@ -488,16 +469,7 @@ PHP_MINIT_FUNCTION(redis)
488469
}
489470

490471
/* RedisException class */
491-
INIT_CLASS_ENTRY(redis_exception_class_entry, "RedisException", NULL);
492-
redis_exception_ce = zend_register_internal_class_ex(
493-
&redis_exception_class_entry,
494-
exception_ce);
495-
496-
/* RedisClusterException class */
497-
INIT_CLASS_ENTRY(redis_cluster_exception_class_entry,
498-
"RedisClusterException", NULL);
499-
redis_cluster_exception_ce = zend_register_internal_class_ex(
500-
&redis_cluster_exception_class_entry, exception_ce);
472+
redis_exception_ce = register_class_RedisException(exception_ce);
501473

502474
/* Add shared class constants to Redis and RedisCluster objects */
503475
add_class_constants(redis_ce, 0);

‎redis.stub.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/**
44
* @generate-function-entries
55
* @generate-legacy-arginfo
6+
* @generate-class-entries
67
*/
78

89
class Redis {
@@ -34,6 +35,7 @@ public function acl(string $subcmd, ...$args);
3435
/** @return int|Redis */
3536
public function append(string $key, mixed $value);
3637

38+
/** @sensitive-param $credentials **/
3739
public function auth(mixed $credentials): bool;
3840

3941
public function bgSave(): bool;
@@ -553,3 +555,5 @@ public function zunion(array $keys, array $weights = null, array $options = null
553555

554556
public function zunionstore(string $dst, array $keys, array $weights = null, string $aggregate = null): int;
555557
}
558+
559+
class RedisException extends RuntimeException {}

‎redis_arginfo.h‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: efcda1ed028d65d0b4848d32133dc0e32f17871f */
2+
* Stub hash: 0e9010a9567392f6f2a8ad7f1f5f09a28a086c45 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct, 0, 0, 0)
55
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 0, "null")
@@ -1436,3 +1436,28 @@ static const zend_function_entry class_Redis_methods[] = {
14361436
ZEND_ME(Redis, zunionstore, arginfo_class_Redis_zunionstore, ZEND_ACC_PUBLIC)
14371437
ZEND_FE_END
14381438
};
1439+
1440+
1441+
static const zend_function_entry class_RedisException_methods[] = {
1442+
ZEND_FE_END
1443+
};
1444+
1445+
static zend_class_entry *register_class_Redis(void)
1446+
{
1447+
zend_class_entry ce, *class_entry;
1448+
1449+
INIT_CLASS_ENTRY(ce, "Redis", class_Redis_methods);
1450+
class_entry = zend_register_internal_class_ex(&ce, NULL);
1451+
1452+
return class_entry;
1453+
}
1454+
1455+
static zend_class_entry *register_class_RedisException(zend_class_entry *class_entry_RuntimeException)
1456+
{
1457+
zend_class_entry ce, *class_entry;
1458+
1459+
INIT_CLASS_ENTRY(ce, "RedisException", class_RedisException_methods);
1460+
class_entry = zend_register_internal_class_ex(&ce, class_entry_RuntimeException);
1461+
1462+
return class_entry;
1463+
}

‎redis_array.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,17 @@ zend_class_entry *redis_array_ce;
4040
#if PHP_VERSION_ID < 80000
4141
#include "redis_array_legacy_arginfo.h"
4242
#else
43+
#include "zend_attributes.h"
4344
#include "redis_array_arginfo.h"
4445
#endif
4546

46-
extern const zend_function_entry *redis_array_get_methods(void)
47+
PHP_MINIT_FUNCTION(redis_array)
4748
{
48-
return class_RedisArray_methods;
49+
/* RedisSentinel class */
50+
redis_array_ce = register_class_RedisArray();
51+
redis_array_ce->create_object = create_redis_array_object;
52+
53+
return SUCCESS;
4954
}
5055

5156
static void

‎redis_array.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ typedef struct RedisArray_ {
3636
struct RedisArray_ *prev;
3737
} RedisArray;
3838

39-
extern const zend_function_entry *redis_array_get_methods(void);
40-
zend_object *create_redis_array_object(zend_class_entry *ce);
41-
void free_redis_array_object(zend_object *object);
39+
extern zend_class_entry *redis_array_ce;
40+
extern PHP_MINIT_FUNCTION(redis_array);
41+
extern zend_object *create_redis_array_object(zend_class_entry *ce);
4242

4343
#endif

‎redis_array.stub.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/**
44
* @generate-function-entries
55
* @generate-legacy-arginfo
6+
* @generate-class-entries
67
*/
78

89
class RedisArray {

‎redis_array_arginfo.h‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: db47879ea03ea74832fe777fcc5d834ea554bb4a */
2+
* Stub hash: fb17c785beccf1dbeedaa48afb4aa7d48fd8b655 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_RedisArray___call, 0, 2, IS_MIXED, 0)
55
ZEND_ARG_TYPE_INFO(0, function_name, IS_STRING, 0)
@@ -176,3 +176,13 @@ static const zend_function_entry class_RedisArray_methods[] = {
176176
ZEND_ME(RedisArray, zscan, arginfo_class_RedisArray_zscan, ZEND_ACC_PUBLIC)
177177
ZEND_FE_END
178178
};
179+
180+
static zend_class_entry *register_class_RedisArray(void)
181+
{
182+
zend_class_entry ce, *class_entry;
183+
184+
INIT_CLASS_ENTRY(ce, "RedisArray", class_RedisArray_methods);
185+
class_entry = zend_register_internal_class_ex(&ce, NULL);
186+
187+
return class_entry;
188+
}

‎redis_array_legacy_arginfo.h‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: db47879ea03ea74832fe777fcc5d834ea554bb4a */
2+
* Stub hash: fb17c785beccf1dbeedaa48afb4aa7d48fd8b655 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisArray___call, 0, 0, 2)
55
ZEND_ARG_INFO(0, function_name)
@@ -173,3 +173,13 @@ static const zend_function_entry class_RedisArray_methods[] = {
173173
ZEND_ME(RedisArray, zscan, arginfo_class_RedisArray_zscan, ZEND_ACC_PUBLIC)
174174
ZEND_FE_END
175175
};
176+
177+
static zend_class_entry *register_class_RedisArray(void)
178+
{
179+
zend_class_entry ce, *class_entry;
180+
181+
INIT_CLASS_ENTRY(ce, "RedisArray", class_RedisArray_methods);
182+
class_entry = zend_register_internal_class_ex(&ce, NULL);
183+
184+
return class_entry;
185+
}

‎redis_cluster.c‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,25 @@ zend_class_entry *redis_cluster_exception_ce;
3838
#if PHP_VERSION_ID < 80000
3939
#include "redis_cluster_legacy_arginfo.h"
4040
#else
41+
#include "zend_attributes.h"
4142
#include "redis_cluster_arginfo.h"
4243
#endif
4344

44-
extern const zend_function_entry *redis_cluster_get_methods(void)
45+
PHP_MINIT_FUNCTION(redis_cluster)
4546
{
46-
return class_RedisCluster_methods;
47+
zend_class_entry *exception_ce = NULL;
48+
49+
redis_cluster_ce = register_class_RedisCluster();
50+
redis_cluster_ce->create_object = create_cluster_context;
51+
52+
/* Base Exception class */
53+
exception_ce = zend_hash_str_find_ptr(CG(class_table), "RuntimeException", sizeof("RuntimeException") - 1);
54+
if (exception_ce == NULL) {
55+
exception_ce = zend_exception_get_default();
56+
}
57+
redis_cluster_exception_ce = register_class_RedisClusterException(exception_ce);
58+
59+
return SUCCESS;
4760
}
4861

4962
/* Handlers for RedisCluster */

0 commit comments

Comments
 (0)