Sitelet https://github.com/phpredis/phpredis/commit/6b411aa8
Skip to content

Commit 6b411aa

Browse files
committed
Issue #1508
Wrap all calls of `call_user_function` into `ra_call_user_function` where AUTH command sended before function call.
1 parent 339cfa2 commit 6b411aa

3 files changed

Lines changed: 44 additions & 30 deletions

File tree

‎redis_array.c‎

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,19 @@ redis_array_get(zval *id TSRMLS_DC)
268268
return NULL;
269269
}
270270

271+
PHP_REDIS_API int
272+
ra_call_user_function(HashTable *function_table, zval *object, zval *function_name, zval *retval_ptr, uint param_count, zval params[] TSRMLS_DC)
273+
{
274+
if (object) {
275+
redis_object *redis = PHPREDIS_GET_OBJECT(redis_object, object);
276+
if (redis->sock->auth && redis->sock->status != REDIS_SOCK_STATUS_CONNECTED) {
277+
redis_sock_server_open(redis->sock TSRMLS_CC);
278+
redis_sock_auth(redis->sock TSRMLS_CC);
279+
}
280+
}
281+
return call_user_function(function_table, object, function_name, retval_ptr, param_count, params);
282+
}
283+
271284
/* {{{ proto RedisArray RedisArray::__construct()
272285
Public constructor */
273286
PHP_METHOD(RedisArray, __construct)
@@ -450,7 +463,7 @@ ra_forward_call(INTERNAL_FUNCTION_PARAMETERS, RedisArray *ra, const char *cmd, i
450463

451464
/* multi/exec */
452465
if(ra->z_multi_exec) {
453-
call_user_function(&redis_ce->function_table, ra->z_multi_exec, &z_fun, return_value, argc, z_callargs);
466+
ra_call_user_function(&redis_ce->function_table, ra->z_multi_exec, &z_fun, return_value, argc, z_callargs TSRMLS_CC);
454467
zval_dtor(return_value);
455468
zval_dtor(&z_fun);
456469
for (i = 0; i < argc; ++i) {
@@ -468,7 +481,7 @@ ra_forward_call(INTERNAL_FUNCTION_PARAMETERS, RedisArray *ra, const char *cmd, i
468481
/* add MULTI + SADD */
469482
ra_index_multi(redis_inst, MULTI TSRMLS_CC);
470483
/* call using discarded temp value and extract exec results after. */
471-
call_user_function(&redis_ce->function_table, redis_inst, &z_fun, return_value, argc, z_callargs);
484+
ra_call_user_function(&redis_ce->function_table, redis_inst, &z_fun, return_value, argc, z_callargs TSRMLS_CC);
472485
zval_dtor(return_value);
473486

474487
/* add keys to index. */
@@ -477,7 +490,7 @@ ra_forward_call(INTERNAL_FUNCTION_PARAMETERS, RedisArray *ra, const char *cmd, i
477490
/* call EXEC */
478491
ra_index_exec(redis_inst, return_value, 0 TSRMLS_CC);
479492
} else { /* call directly through. */
480-
call_user_function(&redis_ce->function_table, redis_inst, &z_fun, return_value, argc, z_callargs);
493+
ra_call_user_function(&redis_ce->function_table, redis_inst, &z_fun, return_value, argc, z_callargs TSRMLS_CC);
481494

482495
if (!b_write_cmd) {
483496
/* check if we have an error. */
@@ -703,7 +716,7 @@ multihost_distribute_call(RedisArray *ra, zval *return_value, zval *z_fun, int a
703716
MAKE_STD_ZVAL(z_tmp);
704717
#endif
705718
/* Call each node in turn */
706-
call_user_function(&redis_array_ce->function_table, &ra->redis[i], z_fun, z_tmp, argc, argv);
719+
ra_call_user_function(&redis_array_ce->function_table, &ra->redis[i], z_fun, z_tmp, argc, argv TSRMLS_CC);
707720

708721
/* Add the result for this host */
709722
add_assoc_zval_ex(return_value, ZSTR_VAL(ra->hosts[i]), ZSTR_LEN(ra->hosts[i]), z_tmp);
@@ -1047,7 +1060,7 @@ PHP_METHOD(RedisArray, mget)
10471060
/* prepare call */
10481061
ZVAL_STRINGL(&z_fun, "MGET", 4);
10491062
/* call MGET on the node */
1050-
call_user_function(&redis_ce->function_table, &ra->redis[n], &z_fun, &z_ret, 1, &z_argarray);
1063+
ra_call_user_function(&redis_ce->function_table, &ra->redis[n], &z_fun, &z_ret, 1, &z_argarray TSRMLS_CC);
10511064
zval_dtor(&z_fun);
10521065

10531066
/* cleanup args array */
@@ -1204,7 +1217,7 @@ PHP_METHOD(RedisArray, mset)
12041217
ZVAL_STRINGL(&z_fun, "MSET", 4);
12051218

12061219
/* call */
1207-
call_user_function(&redis_ce->function_table, &ra->redis[n], &z_fun, &z_ret, 1, &z_argarray);
1220+
ra_call_user_function(&redis_ce->function_table, &ra->redis[n], &z_fun, &z_ret, 1, &z_argarray TSRMLS_CC);
12081221
zval_dtor(&z_fun);
12091222
zval_dtor(&z_ret);
12101223

@@ -1346,7 +1359,7 @@ static void ra_generic_del(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len) {
13461359
}
13471360

13481361
/* call */
1349-
call_user_function(&redis_ce->function_table, &ra->redis[n], &z_fun, &z_ret, 1, &z_argarray);
1362+
ra_call_user_function(&redis_ce->function_table, &ra->redis[n], &z_fun, &z_ret, 1, &z_argarray TSRMLS_CC);
13501363

13511364
if(ra->index) {
13521365
zval_dtor(&z_ret);

‎redis_array.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,6 @@ zend_object *create_redis_array_object(zend_class_entry *ce TSRMLS_DC);
7575
void free_redis_array_object(zend_object *object);
7676
#endif
7777

78+
PHP_REDIS_API int ra_call_user_function(HashTable *function_table, zval *object, zval *function_name, zval *retval_ptr, uint param_count, zval params[] TSRMLS_DC);
7879

7980
#endif

‎redis_array_impl.c‎

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ ra_call_extractor(RedisArray *ra, const char *key, int key_len TSRMLS_DC)
493493
ZVAL_NULL(&z_ret);
494494
/* call extraction function */
495495
ZVAL_STRINGL(&z_argv, key, key_len);
496-
call_user_function(EG(function_table), NULL, &ra->z_fun, &z_ret, 1, &z_argv);
496+
ra_call_user_function(EG(function_table), NULL, &ra->z_fun, &z_ret, 1, &z_argv TSRMLS_CC);
497497

498498
if (Z_TYPE(z_ret) == IS_STRING) {
499499
#if (PHP_MAJOR_VERSION < 7)
@@ -542,7 +542,7 @@ ra_call_distributor(RedisArray *ra, const char *key, int key_len TSRMLS_DC)
542542
ZVAL_NULL(&z_ret);
543543
/* call extraction function */
544544
ZVAL_STRINGL(&z_argv, key, key_len);
545-
call_user_function(EG(function_table), NULL, &ra->z_dist, &z_ret, 1, &z_argv);
545+
ra_call_user_function(EG(function_table), NULL, &ra->z_dist, &z_ret, 1, &z_argv TSRMLS_CC);
546546

547547
ret = (Z_TYPE(z_ret) == IS_LONG) ? Z_LVAL(z_ret) : -1;
548548

@@ -640,7 +640,7 @@ ra_index_multi(zval *z_redis, long multi_value TSRMLS_DC) {
640640
/* run MULTI */
641641
ZVAL_STRINGL(&z_fun_multi, "MULTI", 5);
642642
ZVAL_LONG(&z_args[0], multi_value);
643-
call_user_function(&redis_ce->function_table, z_redis, &z_fun_multi, &z_ret, 1, z_args);
643+
ra_call_user_function(&redis_ce->function_table, z_redis, &z_fun_multi, &z_ret, 1, z_args TSRMLS_CC);
644644
zval_dtor(&z_fun_multi);
645645
zval_dtor(&z_ret);
646646
}
@@ -670,7 +670,7 @@ ra_index_change_keys(const char *cmd, zval *z_keys, zval *z_redis TSRMLS_DC) {
670670
}
671671

672672
/* run cmd */
673-
call_user_function(&redis_ce->function_table, z_redis, &z_fun, &z_ret, argc, z_args);
673+
ra_call_user_function(&redis_ce->function_table, z_redis, &z_fun, &z_ret, argc, z_args TSRMLS_CC);
674674

675675
zval_dtor(&z_args[0]);
676676
zval_dtor(&z_fun);
@@ -731,7 +731,7 @@ ra_index_key(const char *key, int key_len, zval *z_redis TSRMLS_DC) {
731731
ZVAL_STRINGL(&z_args[1], key, key_len);
732732

733733
/* run SADD */
734-
call_user_function(&redis_ce->function_table, z_redis, &z_fun_sadd, &z_ret, 2, z_args);
734+
ra_call_user_function(&redis_ce->function_table, z_redis, &z_fun_sadd, &z_ret, 2, z_args TSRMLS_CC);
735735
zval_dtor(&z_fun_sadd);
736736
zval_dtor(&z_args[1]);
737737
zval_dtor(&z_args[0]);
@@ -745,7 +745,7 @@ ra_index_exec(zval *z_redis, zval *return_value, int keep_all TSRMLS_DC) {
745745

746746
/* run EXEC */
747747
ZVAL_STRINGL(&z_fun_exec, "EXEC", 4);
748-
call_user_function(&redis_ce->function_table, z_redis, &z_fun_exec, &z_ret, 0, NULL);
748+
ra_call_user_function(&redis_ce->function_table, z_redis, &z_fun_exec, &z_ret, 0, NULL TSRMLS_CC);
749749
zval_dtor(&z_fun_exec);
750750

751751
/* extract first element of exec array and put into return_value. */
@@ -772,7 +772,7 @@ ra_index_discard(zval *z_redis, zval *return_value TSRMLS_DC) {
772772

773773
/* run DISCARD */
774774
ZVAL_STRINGL(&z_fun_discard, "DISCARD", 7);
775-
call_user_function(&redis_ce->function_table, z_redis, &z_fun_discard, &z_ret, 0, NULL);
775+
ra_call_user_function(&redis_ce->function_table, z_redis, &z_fun_discard, &z_ret, 0, NULL TSRMLS_CC);
776776

777777
zval_dtor(&z_fun_discard);
778778
zval_dtor(&z_ret);
@@ -785,7 +785,7 @@ ra_index_unwatch(zval *z_redis, zval *return_value TSRMLS_DC) {
785785

786786
/* run UNWATCH */
787787
ZVAL_STRINGL(&z_fun_unwatch, "UNWATCH", 7);
788-
call_user_function(&redis_ce->function_table, z_redis, &z_fun_unwatch, &z_ret, 0, NULL);
788+
ra_call_user_function(&redis_ce->function_table, z_redis, &z_fun_unwatch, &z_ret, 0, NULL TSRMLS_CC);
789789

790790
zval_dtor(&z_fun_unwatch);
791791
zval_dtor(&z_ret);
@@ -825,14 +825,14 @@ ra_get_key_type(zval *z_redis, const char *key, int key_len, zval *z_from, long
825825
/* run TYPE */
826826
ZVAL_NULL(&z_ret);
827827
ZVAL_STRINGL(&z_fun, "TYPE", 4);
828-
call_user_function(&redis_ce->function_table, z_redis, &z_fun, &z_ret, 1, &z_arg);
828+
ra_call_user_function(&redis_ce->function_table, z_redis, &z_fun, &z_ret, 1, &z_arg TSRMLS_CC);
829829
zval_dtor(&z_fun);
830830
zval_dtor(&z_ret);
831831

832832
/* run TYPE */
833833
ZVAL_NULL(&z_ret);
834834
ZVAL_STRINGL(&z_fun, "TTL", 3);
835-
call_user_function(&redis_ce->function_table, z_redis, &z_fun, &z_ret, 1, &z_arg);
835+
ra_call_user_function(&redis_ce->function_table, z_redis, &z_fun, &z_ret, 1, &z_arg TSRMLS_CC);
836836
zval_dtor(&z_fun);
837837
zval_dtor(&z_ret);
838838

@@ -864,7 +864,7 @@ ra_remove_from_index(zval *z_redis, const char *key, int key_len TSRMLS_DC) {
864864
ZVAL_STRINGL(&z_args[0], PHPREDIS_INDEX_NAME, sizeof(PHPREDIS_INDEX_NAME) - 1);
865865
ZVAL_STRINGL(&z_args[1], key, key_len);
866866

867-
call_user_function(&redis_ce->function_table, z_redis, &z_fun_srem, &z_ret, 2, z_args);
867+
ra_call_user_function(&redis_ce->function_table, z_redis, &z_fun_srem, &z_ret, 2, z_args TSRMLS_CC);
868868

869869
/* cleanup */
870870
zval_dtor(&z_fun_srem);
@@ -886,7 +886,7 @@ ra_del_key(const char *key, int key_len, zval *z_from TSRMLS_DC) {
886886
/* run DEL on source */
887887
ZVAL_STRINGL(&z_fun_del, "DEL", 3);
888888
ZVAL_STRINGL(&z_args[0], key, key_len);
889-
call_user_function(&redis_ce->function_table, z_from, &z_fun_del, &z_ret, 1, z_args);
889+
ra_call_user_function(&redis_ce->function_table, z_from, &z_fun_del, &z_ret, 1, z_args TSRMLS_CC);
890890
zval_dtor(&z_fun_del);
891891
zval_dtor(&z_args[0]);
892892
zval_dtor(&z_ret);
@@ -911,7 +911,7 @@ ra_expire_key(const char *key, int key_len, zval *z_to, long ttl TSRMLS_DC) {
911911
ZVAL_STRINGL(&z_fun_expire, "EXPIRE", 6);
912912
ZVAL_STRINGL(&z_args[0], key, key_len);
913913
ZVAL_LONG(&z_args[1], ttl);
914-
call_user_function(&redis_ce->function_table, z_to, &z_fun_expire, &z_ret, 2, z_args);
914+
ra_call_user_function(&redis_ce->function_table, z_to, &z_fun_expire, &z_ret, 2, z_args TSRMLS_CC);
915915
zval_dtor(&z_fun_expire);
916916
zval_dtor(&z_args[0]);
917917
zval_dtor(&z_ret);
@@ -935,7 +935,7 @@ ra_move_zset(const char *key, int key_len, zval *z_from, zval *z_to, long ttl TS
935935
ZVAL_STRINGL(&z_args[1], "0", 1);
936936
ZVAL_STRINGL(&z_args[2], "-1", 2);
937937
ZVAL_BOOL(&z_args[3], 1);
938-
call_user_function(&redis_ce->function_table, z_from, &z_fun_zrange, &z_ret, 4, z_args);
938+
ra_call_user_function(&redis_ce->function_table, z_from, &z_fun_zrange, &z_ret, 4, z_args TSRMLS_CC);
939939
zval_dtor(&z_fun_zrange);
940940
zval_dtor(&z_args[2]);
941941
zval_dtor(&z_args[1]);
@@ -973,7 +973,7 @@ ra_move_zset(const char *key, int key_len, zval *z_from, zval *z_to, long ttl TS
973973

974974
/* run ZADD on target */
975975
ZVAL_STRINGL(&z_fun_zadd, "ZADD", 4);
976-
call_user_function(&redis_ce->function_table, z_to, &z_fun_zadd, &z_ret_dest, 1 + 2 * count, z_zadd_args);
976+
ra_call_user_function(&redis_ce->function_table, z_to, &z_fun_zadd, &z_ret_dest, 1 + 2 * count, z_zadd_args TSRMLS_CC);
977977

978978
/* Expire if needed */
979979
ra_expire_key(key, key_len, z_to, ttl TSRMLS_CC);
@@ -1000,7 +1000,7 @@ ra_move_string(const char *key, int key_len, zval *z_from, zval *z_to, long ttl
10001000
/* run GET on source */
10011001
ZVAL_STRINGL(&z_fun_get, "GET", 3);
10021002
ZVAL_STRINGL(&z_args[0], key, key_len);
1003-
call_user_function(&redis_ce->function_table, z_from, &z_fun_get, &z_ret, 1, z_args);
1003+
ra_call_user_function(&redis_ce->function_table, z_from, &z_fun_get, &z_ret, 1, z_args TSRMLS_CC);
10041004
zval_dtor(&z_fun_get);
10051005

10061006
if(Z_TYPE(z_ret) != IS_STRING) { /* key not found or replaced */
@@ -1016,14 +1016,14 @@ ra_move_string(const char *key, int key_len, zval *z_from, zval *z_to, long ttl
10161016
ZVAL_LONG(&z_args[1], ttl);
10171017
ZVAL_STRINGL(&z_args[2], Z_STRVAL(z_ret), Z_STRLEN(z_ret)); /* copy z_ret to arg 1 */
10181018
zval_dtor(&z_ret); /* free memory from our previous call */
1019-
call_user_function(&redis_ce->function_table, z_to, &z_fun_set, &z_ret, 3, z_args);
1019+
ra_call_user_function(&redis_ce->function_table, z_to, &z_fun_set, &z_ret, 3, z_args TSRMLS_CC);
10201020
/* cleanup */
10211021
zval_dtor(&z_args[2]);
10221022
} else {
10231023
ZVAL_STRINGL(&z_fun_set, "SET", 3);
10241024
ZVAL_STRINGL(&z_args[1], Z_STRVAL(z_ret), Z_STRLEN(z_ret)); /* copy z_ret to arg 1 */
10251025
zval_dtor(&z_ret); /* free memory from our previous return value */
1026-
call_user_function(&redis_ce->function_table, z_to, &z_fun_set, &z_ret, 2, z_args);
1026+
ra_call_user_function(&redis_ce->function_table, z_to, &z_fun_set, &z_ret, 2, z_args TSRMLS_CC);
10271027
/* cleanup */
10281028
zval_dtor(&z_args[1]);
10291029
}
@@ -1041,7 +1041,7 @@ ra_move_hash(const char *key, int key_len, zval *z_from, zval *z_to, long ttl TS
10411041
/* run HGETALL on source */
10421042
ZVAL_STRINGL(&z_args[0], key, key_len);
10431043
ZVAL_STRINGL(&z_fun_hgetall, "HGETALL", 7);
1044-
call_user_function(&redis_ce->function_table, z_from, &z_fun_hgetall, &z_args[1], 1, z_args);
1044+
ra_call_user_function(&redis_ce->function_table, z_from, &z_fun_hgetall, &z_args[1], 1, z_args TSRMLS_CC);
10451045
zval_dtor(&z_fun_hgetall);
10461046

10471047
if (Z_TYPE(z_args[1]) != IS_ARRAY) { /* key not found or replaced */
@@ -1053,7 +1053,7 @@ ra_move_hash(const char *key, int key_len, zval *z_from, zval *z_to, long ttl TS
10531053

10541054
/* run HMSET on target */
10551055
ZVAL_STRINGL(&z_fun_hmset, "HMSET", 5);
1056-
call_user_function(&redis_ce->function_table, z_to, &z_fun_hmset, &z_ret_dest, 2, z_args);
1056+
ra_call_user_function(&redis_ce->function_table, z_to, &z_fun_hmset, &z_ret_dest, 2, z_args TSRMLS_CC);
10571057
zval_dtor(&z_fun_hmset);
10581058
zval_dtor(&z_ret_dest);
10591059

@@ -1088,7 +1088,7 @@ ra_move_collection(const char *key, int key_len, zval *z_from, zval *z_to,
10881088
ZVAL_STRING(&z_retrieve_args[i], cmd_list[i]);
10891089
}
10901090

1091-
call_user_function(&redis_ce->function_table, z_from, &z_fun_retrieve, &z_ret, list_count, z_retrieve_args);
1091+
ra_call_user_function(&redis_ce->function_table, z_from, &z_fun_retrieve, &z_ret, list_count, z_retrieve_args TSRMLS_CC);
10921092

10931093
/* cleanup */
10941094
zval_dtor(&z_fun_retrieve);
@@ -1120,7 +1120,7 @@ ra_move_collection(const char *key, int key_len, zval *z_from, zval *z_to,
11201120
/* Clean up our input return value */
11211121
zval_dtor(&z_ret);
11221122

1123-
call_user_function(&redis_ce->function_table, z_to, &z_fun_sadd, &z_ret, count, z_sadd_args);
1123+
ra_call_user_function(&redis_ce->function_table, z_to, &z_fun_sadd, &z_ret, count, z_sadd_args TSRMLS_CC);
11241124

11251125
/* cleanup */
11261126
zval_dtor(&z_fun_sadd);
@@ -1263,7 +1263,7 @@ ra_rehash_server(RedisArray *ra, zval *z_redis, zend_string *hostname, zend_bool
12631263
ZVAL_STRING(&z_argv, "*");
12641264
}
12651265
ZVAL_NULL(&z_ret);
1266-
call_user_function(&redis_ce->function_table, z_redis, &z_fun, &z_ret, 1, &z_argv);
1266+
ra_call_user_function(&redis_ce->function_table, z_redis, &z_fun, &z_ret, 1, &z_argv TSRMLS_CC);
12671267
zval_dtor(&z_argv);
12681268
zval_dtor(&z_fun);
12691269

0 commit comments

Comments
 (0)