Skip to content

[CRASH] client trackinginfo coredump when tracking is off #1683

Description

@yangbodong22011

step to reproduce

  1. compile valkey unstable branch and start at 6379 port.
  2. use cli connect to 6379 and execute client trackinginfo
  3. then will get coredump
/lib64/libpthread.so.0(+0xf630)[0x7fab74931630]
./src/valkey-server *:6379(clientTrackingInfoCommand+0x12b)[0x57f8db]
./src/valkey-server *:6379(call+0x5ba)[0x5a791a]
./src/valkey-server *:6379(processCommand+0x968)[0x5a8938]
./src/valkey-server *:6379(processInputBuffer+0x18d)[0x58381d]
./src/valkey-server *:6379(readQueryFromClient+0x59)[0x585ea9]
./src/valkey-server *:6379[0x46fa4d]
./src/valkey-server *:6379(aeMain+0x89)[0x5bf3e9]
./src/valkey-server *:6379(main+0x4e1)[0x455821]
/lib64/libc.so.6(__libc_start_main+0xf5)[0x7fab74576555]
./src/valkey-server *:6379[0x4564f2]
  1. gdb will get core at networking.c:4103, because c->pubsub_data is null.
Thread 1 "valkey-server" received signal SIGSEGV, Segmentation fault.
0x000000000057f8db in clientTrackingInfoCommand (c=0x7ffff6c57800) at networking.c:4103
4103	    if (c->pubsub_data->client_tracking_prefixes) {
(gdb) p c
$1 = (client *) 0x7ffff6c57800
(gdb) p c->pubsub_data
$2 = (ClientPubSubData *) 0x0

how to fix

  1. judge c->pubsub_data is null (I prefre)
diff --git a/src/networking.c b/src/networking.c
index 7701ad88c..1a26aa4a2 100644
--- a/src/networking.c
+++ b/src/networking.c
@@ -4100,7 +4100,7 @@ void clientTrackingInfoCommand(client *c) {
 
     /* Prefixes */
     addReplyBulkCString(c, "prefixes");
-    if (c->pubsub_data->client_tracking_prefixes) {
+    if (c->pubsub_data && c->pubsub_data->client_tracking_prefixes) {
         addReplyArrayLen(c, raxSize(c->pubsub_data->client_tracking_prefixes));
  1. when enable tracking, will call initClientPubSubData(), maybe we can also call this when tracking is off.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions