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

Skip to content

Commit 6dc0a0b

Browse files
Fix segfault when passing just false to auth.
Fixes #2430
1 parent f4ede5a commit 6dc0a0b

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

library.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4358,21 +4358,23 @@ redis_read_variant_reply_strings(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_
43584358
return variant_reply_generic(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, 1, 0, z_tab, ctx);
43594359
}
43604360

4361+
/* The user may wish to send us something like [NULL, 'password'] or
4362+
* [false, 'password'] so don't convert NULL or FALSE into "". */
4363+
static int redisTrySetAuthArg(zend_string **dst, zval *zsrc) {
4364+
if (Z_TYPE_P(zsrc) == IS_NULL || Z_TYPE_P(zsrc) == IS_FALSE)
4365+
return FAILURE;
4366+
4367+
*dst = zval_get_string(zsrc);
4368+
4369+
return SUCCESS;
4370+
}
4371+
43614372
PHP_REDIS_API
43624373
int redis_extract_auth_info(zval *ztest, zend_string **user, zend_string **pass) {
43634374
zval *zv;
43644375
HashTable *ht;
43654376
int num;
43664377

4367-
/* The user may wish to send us something like [NULL, 'password'] or
4368-
* [false, 'password'] so don't convert NULL or FALSE into "". */
4369-
#define TRY_SET_AUTH_ARG(zv, ppzstr) \
4370-
do { \
4371-
if (Z_TYPE_P(zv) != IS_NULL && Z_TYPE_P(zv) != IS_FALSE) { \
4372-
*(ppzstr) = zval_get_string(zv); \
4373-
} \
4374-
} while (0)
4375-
43764378
/* Null out user and password */
43774379
*user = *pass = NULL;
43784380

@@ -4382,8 +4384,7 @@ int redis_extract_auth_info(zval *ztest, zend_string **user, zend_string **pass)
43824384

43834385
/* Handle a non-array first */
43844386
if (Z_TYPE_P(ztest) != IS_ARRAY) {
4385-
TRY_SET_AUTH_ARG(ztest, pass);
4386-
return SUCCESS;
4387+
return redisTrySetAuthArg(pass, ztest);
43874388
}
43884389

43894390
/* Handle the array case */
@@ -4400,18 +4401,18 @@ int redis_extract_auth_info(zval *ztest, zend_string **user, zend_string **pass)
44004401
if ((zv = REDIS_HASH_STR_FIND_STATIC(ht, "user")) ||
44014402
(zv = zend_hash_index_find(ht, 0)))
44024403
{
4403-
TRY_SET_AUTH_ARG(zv, user);
4404+
redisTrySetAuthArg(user, zv);
44044405
}
44054406

44064407
if ((zv = REDIS_HASH_STR_FIND_STATIC(ht, "pass")) ||
44074408
(zv = zend_hash_index_find(ht, 1)))
44084409
{
4409-
TRY_SET_AUTH_ARG(zv, pass);
4410+
redisTrySetAuthArg(pass, zv);
44104411
}
44114412
} else if ((zv = REDIS_HASH_STR_FIND_STATIC(ht, "pass")) ||
44124413
(zv = zend_hash_index_find(ht, 0)))
44134414
{
4414-
TRY_SET_AUTH_ARG(zv, pass);
4415+
redisTrySetAuthArg(pass, zv);
44154416
}
44164417

44174418
/* If we at least have a password, we're good */

0 commit comments

Comments
 (0)