Skip to content

Commit 3243f42

Browse files
Switch to snprintf and modify challenge string
* It should be impossible to cause a buffer overrun with this format string but use the safer version anyway. * Make the phpredis challenge string searchable and add 32 bits of entropy since it's theoretically possible that two machines would generate the same `tv_sec` + `tv_usec` string.
1 parent 99ebd0c commit 3243f42

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

library.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,8 +1800,8 @@ redis_sock_create(char *host, int host_len, int port,
18001800
static int
18011801
redis_sock_check_liveness(RedisSock *redis_sock)
18021802
{
1803-
char inbuf[4096], uniqid[32], *response;
1804-
int uniqid_len, response_len;
1803+
char inbuf[4096], uniqid[64];
1804+
int uniqid_len;
18051805
smart_string cmd = {0};
18061806
struct timeval tv;
18071807
size_t len;
@@ -1811,7 +1811,7 @@ redis_sock_check_liveness(RedisSock *redis_sock)
18111811
redis_cmd_append_sstr(&cmd, ZSTR_VAL(redis_sock->auth), ZSTR_LEN(redis_sock->auth));
18121812
}
18131813
gettimeofday(&tv, NULL);
1814-
uniqid_len = sprintf(uniqid, "%08lx%05lx", tv.tv_sec, tv.tv_usec);
1814+
uniqid_len = snprintf(uniqid, sizeof(uniqid), "phpredis_pool:%08lx%05lx:%08" PRIx32, (long)tv.tv_sec, (long)tv.tv_usec, php_mt_rand());
18151815
redis_cmd_init_sstr(&cmd, 1, "PING", sizeof("PING") - 1);
18161816
redis_cmd_append_sstr(&cmd, uniqid, uniqid_len);
18171817
smart_string_0(&cmd);

0 commit comments

Comments
 (0)