8000 Fix for 32-bit integer overflows on large timeouts · jrtkcoder/phpredis@74675fb · GitHub
[go: up one dir, main page]

Skip to content

Commit 74675fb

Browse files
committed
Fix for 32-bit integer overflows on large timeouts
Timeouts in milliseconds overflow longs on 32-bit architectures. This fix replaces the integer return with a float on 32-bit. Ref: GitHub issue phpredis#174.
1 parent 2c1875c commit 74675fb

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

common.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@
44
#ifndef REDIS_COMMON_H
55
#define REDIS_COMMON_H
66

7+
/* Check windows */
8+
#if _WIN32 || _WIN64
9+
#if _WIN64
10+
#define PHP64
11+
#else
12+
#define PHP32
13+
#endif
14+
#endif
15+
16+
/* Check GCC and Clang */
17+
#if __GNUC__
18+
#if __x86_64__ || __ppc64__
19+
#define PHP64
20+
#else
21+
#define PHP32
22+
#endif
23+
#endif
24+
725
#define redis_sock_name "Redis Socket Buffer"
826
#define REDIS_SOCK_STATUS_FAILED 0
927
#define REDIS_SOCK_STATUS_DISCONNECTED 1

redis.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3001,22 +3001,27 @@ PHP_METHOD(Redis, sortDescAlpha)
30013001
PHPAPI void generic_expire_cmd(INTERNAL_FUNCTION_PARAMETERS, char *keyword, int keyword_len) {
30023002
zval *object;
30033003
RedisSock *redis_sock;
3004-
char *key = NULL, *cmd;
3005-
int key_len, cmd_len, key_free;
3006-
long t;
3004+
char *key = NULL, *cmd, *t;
3005+
int key_len, cmd_len, key_free, t_len;
3006+
int i;
30073007

3008-
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osl",
3008+
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oss",
30093009
&object, redis_ce, &key, &key_len,
3010-
&t) == FAILURE) {
3010+
&t, &t_len) == FAILURE) {
30113011
RETURN_FALSE;
30123012
}
30133013

30143014
if (redis_sock_get(object, &redis_sock TSRMLS_CC, 0) < 0) {
30153015
RETURN_FALSE;
30163016
}
30173017

3018+
/* check that we have a number */
3019+
for(i = 0; i < t_len; ++i)
3020+
if(t[i] < '0' || t[i] > '9')
3021+
RETURN_FALSE;
3022+
30183023
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
3019-
cmd_len = redis_cmd_format_static(&cmd, keyword, "sl", key, key_len, t);
3024+
cmd_len = redis_cmd_format_static(&cmd, keyword, "ss", key, key_len, t, t_len);
30203025
if(key_free) efree(key);
30213026

30223027
REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
@@ -3278,10 +3283,17 @@ PHPAPI void generic_ttl(INTERNAL_FUNCTION_PARAMETERS, char *keyword) {
32783283
if(key_free) efree(key);
32793284

32803285
REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
3286+
#ifdef PHP64
32813287
IF_ATOMIC() {
32823288
redis_long_response(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL);
32833289
}
32843290
REDIS_PROCESS_RESPONSE(redis_long_response);
3291+
#else
3292+
IF_ATOMIC() {
3293+
redis_bulk_double_response(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL);
3294+
}
3295+
REDIS_PROCESS_RESPONSE(redis_bulk_double_response);
3296+
#endif
32853297
}
32863298

32873299
/* {{{ proto long Redis::ttl(string key)

0 commit comments

Comments
 (0)
0