Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit faa4bc2

Browse files
Don't cast a uint64_t to a long.
We recently updated PhpRedis to handle `SCAN` cursors > 2^63 as strings (as internally PHP integers are longs). However, the `redis_build_scan_cmd` took the cursor as a long, which would overflow if the value was > `2^63`. This commit simply changes the function to take a `uint64_t` and call our specific `redis_append_sstr_u64` so we send the cursor to Redis correctly. Fixes #2454.
1 parent 3f8dba6 commit faa4bc2

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

redis.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2694,9 +2694,9 @@ PHP_METHOD(Redis, copy) {
26942694
/* }}} */
26952695

26962696
/* Helper to format any combination of SCAN arguments */
2697-
PHP_REDIS_API int
2697+
static int
26982698
redis_build_scan_cmd(char **cmd, REDIS_SCAN_TYPE type, char *key, int key_len,
2699-
long iter, char *pattern, int pattern_len, int count,
2699+
uint64_t cursor, char *pattern, int pattern_len, int count,
27002700
zend_string *match_type)
27012701
{
27022702
smart_string cmdstr = {0};
@@ -2727,7 +2727,7 @@ redis_build_scan_cmd(char **cmd, REDIS_SCAN_TYPE type, char *key, int key_len,
27272727
/* Start the command */
27282728
redis_cmd_init_sstr(&cmdstr, argc, keyword, strlen(keyword));
27292729
if (key_len) redis_cmd_append_sstr(&cmdstr, key, key_len);
2730-
redis_cmd_append_sstr_long(&cmdstr, iter);
2730+
redis_cmd_append_sstr_u64(&cmdstr, cursor);
27312731

27322732
/* Append COUNT if we've got it */
27332733
if(count) {
@@ -2751,7 +2751,7 @@ redis_build_scan_cmd(char **cmd, REDIS_SCAN_TYPE type, char *key, int key_len,
27512751
return cmdstr.len;
27522752
}
27532753

2754-
/* {{{ proto redis::scan(&$iterator, [pattern, [count, [type]]]) */
2754+
/* {{{ proto redis::scan(&$cursor, [pattern, [count, [type]]]) */
27552755
PHP_REDIS_API void
27562756
generic_scan_cmd(INTERNAL_FUNCTION_PARAMETERS, REDIS_SCAN_TYPE type) {
27572757
zval *object, *z_cursor;
@@ -2818,7 +2818,7 @@ generic_scan_cmd(INTERNAL_FUNCTION_PARAMETERS, REDIS_SCAN_TYPE type) {
28182818
* pattern. phpredis can be set up to abstract this from the user, by
28192819
* setting OPT_SCAN to REDIS_SCAN_RETRY. Otherwise we will return empty
28202820
* keys and the user will need to make subsequent calls with an updated
2821-
* iterator.
2821+
* cursor.
28222822
*/
28232823
do {
28242824
/* Free our previous reply if we're back in the loop. We know we are
@@ -2829,10 +2829,10 @@ generic_scan_cmd(INTERNAL_FUNCTION_PARAMETERS, REDIS_SCAN_TYPE type) {
28292829
}
28302830

28312831
// Format our SCAN command
2832-
cmd_len = redis_build_scan_cmd(&cmd, type, key, key_len, (long)cursor,
2833-
pattern, pattern_len, count, match_type);
2832+
cmd_len = redis_build_scan_cmd(&cmd, type, key, key_len, cursor,
2833+
pattern, pattern_len, count, match_type);
28342834

2835-
/* Execute our command getting our new iterator value */
2835+
/* Execute our command getting our new cursor value */
28362836
REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
28372837
if(redis_sock_read_scan_reply(INTERNAL_FUNCTION_PARAM_PASSTHRU,
28382838
redis_sock,type, &cursor) < 0)
@@ -2853,7 +2853,7 @@ generic_scan_cmd(INTERNAL_FUNCTION_PARAMETERS, REDIS_SCAN_TYPE type) {
28532853
/* Free our key if it was prefixed */
28542854
if(key_free) efree(key);
28552855

2856-
/* Update our iterator reference */
2856+
/* Update our cursor reference */
28572857
redisSetScanCursor(z_cursor, cursor);
28582858
}
28592859

0 commit comments

Comments
 (0)