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

Skip to content

Commit 4a0a46b

Browse files
committed
Check number of elements in incoming array-argument
1 parent e5660be commit 4a0a46b

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

redis_array.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,9 @@ ra_forward_call(INTERNAL_FUNCTION_PARAMETERS, RedisArray *ra, const char *cmd, i
394394
zend_bool b_write_cmd = 0;
395395

396396
h_args = Z_ARRVAL_P(z_args);
397-
argc = zend_hash_num_elements(h_args);
397+
if ((argc = zend_hash_num_elements(h_args)) == 0) {
398+
RETURN_FALSE;
399+
}
398400

399401
if(ra->z_multi_exec) {
400402
redis_inst = ra->z_multi_exec; /* we already have the instance */
@@ -935,7 +937,9 @@ PHP_METHOD(RedisArray, mget)
935937

936938
/* init data structures */
937939
h_keys = Z_ARRVAL_P(z_keys);
938-
argc = zend_hash_num_elements(h_keys);
940+
if ((argc = zend_hash_num_elements(h_keys)) == 0) {
941+
RETURN_FALSE;
942+
}
939943
argv = emalloc(argc * sizeof(zval*));
940944
pos = emalloc(argc * sizeof(int));
941945

@@ -1087,7 +1091,9 @@ PHP_METHOD(RedisArray, mset)
10871091

10881092
/* init data structures */
10891093
h_keys = Z_ARRVAL_P(z_keys);
1090-
argc = zend_hash_num_elements(h_keys);
1094+
if ((argc = zend_hash_num_elements(h_keys)) == 0) {
1095+
RETURN_FALSE;
1096+
}
10911097
argv = emalloc(argc * sizeof(zval*));
10921098
pos = emalloc(argc * sizeof(int));
10931099
keys = emalloc(argc * sizeof(char*));
@@ -1234,7 +1240,11 @@ PHP_METHOD(RedisArray, del)
12341240

12351241
/* init data structures */
12361242
h_keys = Z_ARRVAL(z_keys);
1237-
argc = zend_hash_num_elements(h_keys);
1243+
if ((argc = zend_hash_num_elements(h_keys)) == 0) {
1244+
if (free_zkeys) zval_dtor(&z_keys);
1245+
efree(z_args);
1246+
RETURN_FALSE;
1247+
}
12381248
argv = emalloc(argc * sizeof(zval*));
12391249
pos = emalloc(argc * sizeof(int));
12401250

redis_array_impl.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,7 @@ ra_make_array(HashTable *hosts, zval *z_fun, zval *z_dist, HashTable *hosts_prev
344344
int i, count;
345345
RedisArray *ra;
346346

347-
if (!hosts) return NULL;
348-
count = zend_hash_num_elements(hosts);
347+
if (!hosts || (count = zend_hash_num_elements(hosts)) == 0) return NULL;
349348

350349
/* create object */
351350
ra = emalloc(sizeof(RedisArray));

0 commit comments

Comments
 (0)