From 34fa7b137e6da6ddb0a215cb577fe9f834f88ca3 Mon Sep 17 00:00:00 2001 From: Bonsai Date: Mon, 1 Mar 2021 00:18:14 -0600 Subject: [PATCH] fix: call CLIENT INFO from redis module will crash the server (#8560) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Because when the RM_Call is invoked. It will create a faker client. The point is client connection is NULL, so server will crash in connGetInfo Co-authored-by: Viktor Söderqvist --- src/connection.c | 2 +- tests/unit/moduleapi/misc.tcl | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/connection.c b/src/connection.c index 3e2021fb5..a59463220 100644 --- a/src/connection.c +++ b/src/connection.c @@ -427,7 +427,7 @@ int connGetState(connection *conn) { * For sockets, we always return "fd=" to maintain compatibility. */ const char *connGetInfo(connection *conn, char *buf, size_t buf_len) { - snprintf(buf, buf_len-1, "fd=%i", conn->fd); + snprintf(buf, buf_len-1, "fd=%i", conn == NULL ? -1 : conn->fd); return buf; } diff --git a/tests/unit/moduleapi/misc.tcl b/tests/unit/moduleapi/misc.tcl index b5cd6100c..a6a7a78f9 100644 --- a/tests/unit/moduleapi/misc.tcl +++ b/tests/unit/moduleapi/misc.tcl @@ -111,4 +111,8 @@ start_server {tags {"modules"}} { r test.log_tsctx "info" "Test message" verify_log_message 0 "* Test message*" 0 } + + test {test RM_Call CLIENT INFO} { + assert_match "*fd=-1*" [r test.call_generic client info] + } }