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

Skip to content

Commit c687a51

Browse files
committed
* retab, some files had tabs instead of 4 spaces
* When converting zval from heap -> stack allocation some frees were left, causing invalid frees on stack values * zend_parse* was use int instead of size_t when consuming strings, causing undefined behavior
1 parent 6b3e773 commit c687a51

File tree

7 files changed

+280
-296
lines changed

7 files changed

+280
-296
lines changed

cluster_library.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2394,4 +2394,4 @@ int mbulk_resp_loop_assoc(RedisSock *redis_sock, zval *z_result,
23942394
return SUCCESS;
23952395
}
23962396

2397-
/* vim: set tabstop=4 softtabstops=4 noexpandtab shiftwidth=4: */
2397+
/* vim: set tabstop=4 softtabstop=4 noexpandtab shiftwidth=4: */

library.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ PHP_REDIS_API int redis_check_eof(RedisSock *redis_sock, int no_throw TSRMLS_DC)
165165
}
166166
// Wait for a while before trying to reconnect
167167
if (redis_sock->retry_interval) {
168-
// Random factor to avoid having several (or many) concurrent connections trying to reconnect at the same time
169-
long retry_interval = (count ? redis_sock->retry_interval : (php_rand(TSRMLS_C) % redis_sock->retry_interval));
170-
usleep(retry_interval);
168+
// Random factor to avoid having several (or many) concurrent connections trying to reconnect at the same time
169+
long retry_interval = (count ? redis_sock->retry_interval : (php_rand(TSRMLS_C) % redis_sock->retry_interval));
170+
usleep(retry_interval);
171171
}
172172
redis_sock_connect(redis_sock TSRMLS_CC); /* reconnect */
173173
if(redis_sock->stream) { /* check for EOF again. */
@@ -521,7 +521,7 @@ PHP_REDIS_API char *redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_D
521521

522522
case '+':
523523
case ':':
524-
/* Single Line Reply */
524+
/* Single Line Reply */
525525
/* :123\r\n */
526526
*buf_len = strlen(inbuf) - 2;
527527
if(*buf_len >= 2) {
@@ -959,10 +959,11 @@ PHP_REDIS_API void redis_parse_info_response(char *response, zval *z_ret) {
959959

960960
if(is_numeric == 1) {
961961
add_assoc_long(z_ret, key, atol(value));
962-
efree(value);
963962
} else {
964963
add_assoc_string(z_ret, key, value);
965964
}
965+
efree(value);
966+
966967
efree(key);
967968
}
968969
}
@@ -1257,8 +1258,6 @@ static void array_zip_values_and_scores(RedisSock *redis_sock, zval *z_tab,
12571258
zval_dtor(z_tab);
12581259
ZVAL_DUP(z_tab, &z_ret);
12591260
zval_dtor(&z_ret);
1260-
1261-
efree(&z_ret);
12621261
}
12631262

12641263
static int
@@ -1305,7 +1304,6 @@ redis_mbulk_reply_zipped(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
13051304
} else {
13061305
ZVAL_DUP(return_value, &z_multi_result);
13071306
zval_dtor(&z_multi_result);
1308-
efree(&z_multi_result);
13091307
}
13101308

13111309
return 0;
@@ -1436,6 +1434,7 @@ redis_ping_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
14361434
} else {
14371435
RETURN_STRINGL(response, response_len);
14381436
}
1437+
efree(response);
14391438
}
14401439

14411440
/* Response for DEBUG object which is a formatted single line reply */
@@ -1838,7 +1837,6 @@ PHP_REDIS_API int redis_mbulk_reply_raw(INTERNAL_FUNCTION_PARAMETERS, RedisSock
18381837
add_next_index_zval(z_tab, &z_multi_result);
18391838
} else {
18401839
ZVAL_DUP(return_value, &z_multi_result);
1841-
efree(&z_multi_result);
18421840
}
18431841
/*zval_copy_ctor(return_value); */
18441842
return 0;
@@ -1936,7 +1934,6 @@ PHP_REDIS_API int redis_mbulk_reply_assoc(INTERNAL_FUNCTION_PARAMETERS, RedisSoc
19361934
} else {
19371935
ZVAL_DUP(return_value, &z_multi_result);
19381936
zval_dtor(&z_multi_result);
1939-
efree(&z_multi_result);
19401937
}
19411938
return 0;
19421939
}
@@ -2021,7 +2018,6 @@ redis_serialize(RedisSock *redis_sock, zval *z, char **val, int *val_len
20212018
convert_to_string(&z_copy);
20222019
*val = Z_STRVAL_P(&z_copy);
20232020
*val_len = Z_STRLEN_P(&z_copy);
2024-
efree(&z_copy);
20252021
return 1;
20262022

20272023
case REDIS_SERIALIZER_PHP:
@@ -2316,6 +2312,7 @@ redis_read_variant_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
23162312
int reply_info;
23172313
//char *bulk_resp;
23182314
zval z_ret, *z_ret_p;
2315+
z_ret_p = &z_ret;
23192316

23202317
// Attempt to read our header
23212318
if(redis_read_reply_type(redis_sock,&reply_type,&reply_info TSRMLS_CC) < 0)
@@ -2358,7 +2355,7 @@ redis_read_variant_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
23582355
} else {
23592356
/* Set our return value */
23602357
ZVAL_DUP(return_value, z_ret_p);
2361-
zval_dtor(z_ret_p);
2358+
zval_dtor(z_ret_p);
23622359
efree(z_ret_p);
23632360
}
23642361

0 commit comments

Comments
 (0)