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

Skip to content

Commit af89755

Browse files
Fixed checking for our z_option rather than z_value types
Actually check to make sure the option IS_STRING :) Use is_numeric_string on the port in SENTINEL MONITOR command to better allow for numbers or numeric strings to be passed, while still validating that they're correct Addresses phpredis#449
1 parent 2470ba2 commit af89755

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

redis.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6472,6 +6472,7 @@ sentinel_monitor_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, char *
64726472
{
64736473
char *cmd;
64746474
int cmd_len;
6475+
long port;
64756476

64766477
// Sanity checks
64776478
if(!master || !master_len) {
@@ -6483,24 +6484,31 @@ sentinel_monitor_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, char *
64836484
RETURN_FALSE;
64846485
}
64856486
if(!z_port || (Z_TYPE_P(z_port) != IS_LONG && Z_TYPE_P(z_port) != IS_STRING)) {
6486-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Warning: Must specify a valid port as a string or long");
6487+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Warning: Must specify port as a string or long");
64876488
RETURN_FALSE;
64886489
}
64896490
if(quorum < 0) {
64906491
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Warning: Must specify a valid quorum value");
64916492
RETURN_FALSE;
64926493
}
64936494

6494-
if(Z_TYPE_P(z_port) == IS_LONG) {
6495-
cmd_len = redis_cmd_format_static(&cmd, "SENTINEL", "sssll", "MONITOR", sizeof("MONITOR")-1,
6496-
master, master_len, Z_STRVAL_P(z_ip), Z_STRLEN_P(z_ip),
6497-
Z_LVAL_P(z_port), quorum);
6495+
// Attempt to get the long value of a string if that's what we were passed
6496+
if(Z_TYPE_P(z_port) == IS_STRING) {
6497+
if(is_numeric_string(Z_STRVAL_P(z_port), Z_STRLEN_P(z_port), &port, NULL, 0)!=IS_LONG) {
6498+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Warning: Passed port does not contain a valid number!");
6499+
RETURN_FALSE;
6500+
}
64986501
} else {
6499-
cmd_len = redis_cmd_format_static(&cmd, "SENTINEL", "ssssl", "MONITOR", sizeof("MONITOR")-1,
6500-
master, master_len, Z_STRVAL_P(z_ip), Z_STRLEN_P(z_ip),
6501-
Z_STRVAL_P(z_port), Z_STRLEN_P(z_port), quorum);
6502+
port = Z_LVAL_P(z_port);
65026503
}
65036504

6505+
// Get numeric representation of our port
6506+
port = Z_TYPE_P(z_port) == IS_STRING ? atoi(Z_STRVAL_P(z_port)) : Z_LVAL_P(z_port);
6507+
6508+
cmd_len = redis_cmd_format_static(&cmd, "SENTINEL", "sssll", "MONITOR", sizeof("MONITOR")-1,
6509+
master, master_len, Z_STRVAL_P(z_ip), Z_STRLEN_P(z_ip),
6510+
port, quorum);
6511+
65046512
REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
65056513
IF_ATOMIC() {
65066514
redis_boolean_response(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL);
@@ -6543,12 +6551,12 @@ sentinel_set_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, char *mast
65436551
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Warning: Must specify a master name");
65446552
RETURN_FALSE;
65456553
}
6546-
if(!z_option || !Z_TYPE_P(z_option) || !Z_STRLEN_P(z_option)) {
6554+
if(!z_option || Z_TYPE_P(z_option) != IS_STRING || !Z_STRLEN_P(z_option)) {
65476555
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Warning: Must specify option name");
65486556
RETURN_FALSE;
65496557
}
6550-
if(!z_value || (Z_TYPE_P(z_option) != IS_STRING && Z_TYPE_P(z_option) != IS_LONG &&
6551-
Z_TYPE_P(z_option) != IS_DOUBLE))
6558+
if(!z_value || (Z_TYPE_P(z_value) != IS_STRING && Z_TYPE_P(z_value) != IS_LONG &&
6559+
Z_TYPE_P(z_value) != IS_DOUBLE))
65526560
{
65536561
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Warning: Must specify a valid option value!");
65546562
RETURN_FALSE;

0 commit comments

Comments
 (0)