8000 * Finish int -> size_t move · jrtkcoder/phpredis@33bb629 · GitHub
[go: up one dir, main page]

Skip to content

Commit 33bb629

Browse files
committed
* Finish int -> size_t move
* Fix a few cases where operations were performed on un-initalized stack values
1 parent 9c2cdc7 commit 33bb629

File tree

7 files changed

+118
-119
lines changed

7 files changed

+118
-119
lines changed

cluster_library.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ cluster_multibulk_resp_recursive(RedisSock *sock, size_t elements,
136136
switch(r->type) {
137137
case TYPE_ERR:
138138
case TYPE_LINE:
139-
//TODO Sean-Der
140-
if(redis_sock_gets(sock, buf, sizeof(buf), (size_t *) &r->len) < 0) {
139+
if(redis_sock_gets(sock, buf, sizeof(buf), &r->len) < 0) {
141140
*err = 1;
142141
return;
143142
}
@@ -409,7 +408,7 @@ static clusterKeyVal *cluster_dl_add_key(clusterDistList *dl, char *key,
409408
/* Add a key, returning a pointer to the entry where passed for easy adding
410409
* of values to match this key */
411410
int cluster_dist_add_key(redisCluster *c, HashTable *ht, char *key,
412-
int key_len, clusterKeyVal **kv)
411+
size_t key_len, clusterKeyVal **kv)
413412
{
414413
int key_free;
415414
short slot;
@@ -448,7 +447,8 @@ void cluster_dist_add_val(redisCluster *c, clusterKeyVal *kv, zval *z_val
448447
TSRMLS_DC)
449448
{
450449
char *val;
451-
int val_len, val_free;
450+
int val_free;
451+
size_t val_len;
452452

453453
// Serialize our value
454454
val_free = redis_serialize(c->flags, z_val, &val, &val_len TSRMLS_CC);

cluster_library.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ typedef struct clusterMultiCmd {
313313
typedef struct clusterReply {
314314
REDIS_REPLY_TYPE type; /* Our reply type */
315315
size_t integer; /* Integer reply */
316-
long long len; /* Length of our string */
316+
size_t len; /* Length of our string */
317317
char *str; /* String reply */
318318
size_t elements; /* Count of array elements */
319319
struct clusterReply **element; /* Array elements */
@@ -329,7 +329,7 @@ void cluster_free_reply(clusterReply *reply, int free_data);
329329
HashTable *cluster_dist_create();
330330
void cluster_dist_free(HashTable *ht);
331331
int cluster_dist_add_key(redisCluster *c, HashTable *ht, char *key,
332-
int key_len, clusterKeyVal **kv);
332+
size_t key_len, clusterKeyVal **kv);
333333
void cluster_dist_add_val(redisCluster *c, clusterKeyVal *kv, zval *val
334334
TSRMLS_DC);
335335

library.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,7 +1977,7 @@ PHP_REDIS_API void redis_free_socket(RedisSock *redis_sock)
19771977
}
19781978

19791979
PHP_REDIS_API int
1980-
redis_serialize(RedisSock *redis_sock, zval *z, char **val, int *val_len
1980+
redis_serialize(RedisSock *redis_sock, zval *z, char **val, size_t *val_len
19811981
TSRMLS_DC)
19821982
{
19831983
#if ZEND_MODULE_API_NO >= 20100000
@@ -2049,7 +2049,7 @@ redis_unserialize(RedisSock* redis_sock, const char *val, int val_len,
20492049
{
20502050

20512051
php_unserialize_data_t var_hash;
2052-
int ret, rv_free = 0;
2052+
int ret;
20532053

20542054
switch(redis_sock->serializer) {
20552055
case REDIS_SERIALIZER_NONE:
@@ -2059,7 +2059,6 @@ redis_unserialize(RedisSock* redis_sock, const char *val, int val_len,
20592059
PHP_VAR_UNSERIALIZE_INIT(var_hash);
20602060
if(!php_var_unserialize(*return_value, (const unsigned char**)&val,
20612061
(const unsigned char*)val + val_len, &var_hash TSRMLS_CC)) {
2062-
if(rv_free==1) efree(*return_value);
20632062
ret = 0;
20642063
} else {
20652064
ret = 1;
@@ -2074,17 +2073,11 @@ redis_unserialize(RedisSock* redis_sock, const char *val, int val_len,
20742073

20752074
case REDIS_SERIALIZER_IGBINARY:
20762075
#ifdef HAVE_REDIS_IGBINARY
2077-
if(!*return_value) {
2078-
// TODO Sean-Der, heap allocation
2079-
//MAKE_STD_ZVAL(*return_value);
2080-
rv_free = 1;
2081-
}
20822076
if(igbinary_unserialize((const uint8_t *)val, (size_t)val_len,
20832077
return_value TSRMLS_CC) == 0)
20842078
{
20852079
return 1;
20862080
}
2087-
if (rv_free==1) efree(*return_value);
20882081
#endif
20892082
return 0;
20902083
break;
@@ -2093,7 +2086,7 @@ redis_unserialize(RedisSock* redis_sock, const char *val, int val_len,
20932086
}
20942087

20952088
PHP_REDIS_API int
2096-
redis_key_prefix(RedisSock *redis_sock, char **key, int *key_len) {
2089+
redis_key_prefix(RedisSock *redis_sock, char **key, size_t *key_len) {
20972090
int ret_len;
20982091
char *ret;
20992092

library.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ PHP_REDIS_API void redis_send_discard(INTERNAL_FUNCTION_PARAMETERS, RedisSock *r
6060
PHP_REDIS_API int redis_sock_set_err(RedisSock *redis_sock, const char *msg, int msg_len);
6161

6262
PHP_REDIS_API int
63-
redis_serialize(RedisSock *redis_sock, zval *z, char **val, int *val_len TSRMLS_DC);
63+
redis_serialize(RedisSock *redis_sock, zval *z, char **val, size_t *val_len TSRMLS_DC);
6464
PHP_REDIS_API int
65-
redis_key_prefix(RedisSock *redis_sock, char **key, int *key_len);
65+
redis_key_prefix(RedisSock *redis_sock, char **key, size_t *key_len);
6666

6767
PHP_REDIS_API int
6868
redis_unserialize(RedisSock *redis_sock, const char *val, int val_len, zval **return_value TSRMLS_DC);

redis.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -991,9 +991,10 @@ PHP_METHOD(Redis, getMultiple)
991991
zend_hash_move_forward_ex(hash, &ptr))
992992
{
993993
char *key;
994-
int key_len, key_free;
994+
int key_free;
995+
size_t key_len;
995996
zval z_tmp;
996-
ZVAL_UNDEF(&z_tmp);
997+
ZVAL_UNDEF(&z_tmp);
997998

998999
/* If the key isn't a string, turn it into one */
9991000
if(Z_TYPE_P(z_ele) == IS_STRING) {
@@ -1002,7 +1003,7 @@ PHP_METHOD(Redis, getMultiple)
10021003
} else {
10031004
ZVAL_DUP(&z_tmp, z_ele);
10041005

1005-
convert_to_string(&z_tmp);
1006+
convert_to_string(&z_tmp);
10061007
key = Z_STRVAL(z_tmp);
10071008
key_len = Z_STRLEN(z_tmp);
10081009
}
@@ -1449,8 +1450,7 @@ PHP_REDIS_API void generic_sort_cmd(INTERNAL_FUNCTION_PARAMETERS, char *sort,
14491450
cmd_sizes[2] = 4;
14501451

14511452
/* Prefix our key if we need to */
1452-
//TODO Sean-Der
1453-
key_free = redis_key_prefix(redis_sock, &key, (int *) &key_len);
1453+
key_free = redis_key_prefix(redis_sock, &key, &key_len);
14541454

14551455
/* second line, key */
14561456
cmd_sizes[3] = redis_cmd_format(&cmd_lines[3], "$%d", key_len);
@@ -1853,8 +1853,7 @@ generic_mset(INTERNAL_FUNCTION_PARAMETERS, char *kw, ResultCallback fun) {
18531853

18541854
zend_string *key_zstr;
18551855
char *val, *key;
1856-
unsigned int key_len;
1857-
int val_len;
1856+
size_t val_len, key_len;
18581857
unsigned long idx;
18591858
int type;
18601859
zval *z_value_p;
@@ -1879,18 +1878,18 @@ generic_mset(INTERNAL_FUNCTION_PARAMETERS, char *kw, ResultCallback fun) {
18791878
key_len = key_zstr->len;
18801879
key = key_zstr->val;
18811880

1882-
// When not an integer key, the length will include the \0
1883-
if (key_len > 0) {
1884-
key_len--;
1885-
}
1881+
// When not an integer key, the length will include the \0
1882+
if (key_len > 0) {
1883+
key_len--;
1884+
}
18861885
}
18871886

18881887
if(step == 0)
18891888
argc++; /* found a valid arg */
18901889

18911890
val_free = redis_serialize(redis_sock, z_value_p, &val, &val_len
18921891
TSRMLS_CC);
1893-
key_free = redis_key_prefix(redis_sock, &key, (int*)&key_len);
1892+
key_free = redis_key_prefix(redis_sock, &key, &key_len);
18941893

18951894
if(step == 0) { /* counting */
18961895
cmd_len += 1 + integer_length(key_len) + 2
@@ -2912,7 +2911,8 @@ redis_build_pubsub_cmd(RedisSock *redis_sock, char **ret, PUBSUB_TYPE type,
29122911
HashPosition ptr;
29132912
zval *z_ele;
29142913
char *key;
2915-
int cmd_len, key_len, key_free;
2914+
size_t key_len;
2915+
int cmd_len, key_free;
29162916
smart_string cmd = {0};
29172917

29182918
if(type == PUBSUB_CHANNELS) {
@@ -2952,9 +2952,10 @@ redis_build_pubsub_cmd(RedisSock *redis_sock, char **ret, PUBSUB_TYPE type,
29522952
zend_hash_move_forward_ex(ht_chan, &ptr))
29532953
{
29542954
char *key;
2955-
int key_len, key_free;
2955+
int key_free;
2956+
size_t key_len;
29562957
zval z_tmp;
2957-
ZVAL_UNDEF(&z_tmp);
2958+
ZVAL_UNDEF(&z_tmp);
29582959

29592960
if(Z_TYPE_P(z_ele) == IS_STRING) {
29602961
key = Z_STRVAL_P(z_ele);
@@ -3107,7 +3108,8 @@ redis_build_eval_cmd(RedisSock *redis_sock, char **ret, char *keyword,
31073108
{
31083109
zval z_tmp;
31093110
char *key, *old_cmd;
3110-
int key_len, key_free;
3111+
int key_free;
3112+
size_t key_len;
31113113

31123114
if(Z_TYPE_P(elem) == IS_STRING) {
31133115
key = Z_STRVAL_P(elem);
@@ -3377,8 +3379,7 @@ PHP_METHOD(Redis, migrate) {
33773379
}
33783380

33793381
// Prefix our key if we need to, build our command
3380-
// TODO Sean-Der< F438 /div>
3381-
key_free = redis_key_prefix(redis_sock, &key, (int *) &key_len);
3382+
key_free = redis_key_prefix(redis_sock, &key, &key_len);
33823383

33833384
/* Construct our command */
33843385
if(copy && replace) {
@@ -3740,7 +3741,7 @@ redis_build_scan_cmd(char **cmd, REDIS_SCAN_TYPE type, char *key, int key_len,
37403741
int iter, char *pattern, int pattern_len, int count)
37413742
{
37423743
char *keyword;
3743-
int arg_count, cmd_len;
3744+
int arg_count = 0, cmd_len;
37443745

37453746
/* Count our arguments +1 for key if it's got one, and + 2 for pattern */
37463747
/* or count given that they each carry keywords with them. */
@@ -3799,7 +3800,7 @@ generic_scan_cmd(INTERNAL_FUNCTION_PARAMETERS, REDIS_SCAN_TYPE type) {
37993800
RedisSock *redis_sock;
38003801
HashTable *hash;
38013802
char *pattern=NULL, *cmd, *key=NULL;
3802-
size_t key_len, pattern_len;
3803+
size_t key_len = 0, pattern_len = 0;
38033804
int cmd_len, num_elements, key_free=0;
38043805
long count=0, iter;
38053806

@@ -3852,9 +3853,8 @@ generic_scan_cmd(INTERNAL_FUNCTION_PARAMETERS, REDIS_SCAN_TYPE type) {
38523853
}
38533854

38543855
/* Prefix our key if we've got one and we have a prefix set */
3855-
//TODO Sean-Der
38563856
if(key_len) {
3857-
key_free = redis_key_prefix(redis_sock, &key, (int *) &key_len);
3857+
key_free = redis_key_prefix(redis_sock, &key, &key_len);
38583858
}
38593859

38603860
/**

redis_cluster.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -524,11 +524,13 @@ typedef struct clusterKeyValHT {
524524
char kbuf[22];
525525

526526
char *key;
527-
int key_len, key_free;
527+
size_t key_len;
528+
int key_free;
528529
short slot;
529530

530531
char *val;
531-
int val_len, val_free;
532+
size_t val_len;
533+
int val_free;
532534
} clusterKeyValHT;
533535

534536
/* Helper to pull a key/value pair from a HashTable */
@@ -959,8 +961,7 @@ PHP_METHOD(RedisCluster, keys) {
959961
}
960962

961963
/* Prefix and then build our command */
962-
//TODO Sean-Der
963-
pat_free = redis_key_prefix(c->flags, &pat, (int *) &pat_len);
964+
pat_free = redis_key_prefix(c->flags, &pat, &pat_len);
964965
cmd_len = redis_cmd_format_static(&cmd, "KEYS", "s", pat, pat_len);
965966
if(pat_free) efree(pat);
966967

@@ -1807,8 +1808,8 @@ static void cluster_eval_cmd(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c,
18071808
{
18081809
redisClusterNode *node=NULL;
18091810
char *lua, *key;
1810-
int key_free, args_count=0, key_len;
1811-
size_t lua_len;
1811+
int key_free, args_count=0;
1812+
size_t lua_len, key_len;
18121813
zval *z_arr=NULL, *z_ele;
18131814
HashTable *ht_arr;
18141815
HashPosition ptr;
@@ -2208,7 +2209,8 @@ PHP_METHOD(RedisCluster, discard) {
22082209
static short
22092210
cluster_cmd_get_slot(redisCluster *c, zval *z_arg TSRMLS_DC)
22102211
{
2211-
int key_len, key_free;
2212+
int key_free;
2213+
size_t key_len;
22122214
zval *z_host, *z_port, z_tmp;
22132215
short slot;
22142216
char *key;
@@ -2406,8 +2408,7 @@ static void cluster_kscan_cmd(INTERNAL_FUNCTION_PARAMETERS,
24062408
}
24072409

24082410
// Apply any key prefix we have, get the slot
2409-
// TODO Sean-Der
2410-
key_free = redis_key_prefix(c->flags, &key, (int *) &key_len);
2411+
key_free = redis_key_prefix(c->flags, &key, &key_len);
24112412
slot = cluster_hash_key(key, key_len);
24122413

24132414
// If SCAN_RETRY is set, loop until we get a zero iterator or until

0 commit comments

Comments
 (0)
0