Snapchat / KeyDB

A Multithreaded Fork of Redis
https://keydb.dev
BSD 3-Clause "New" or "Revised" License
11.02k stars 564 forks source link

[BUG] Missing check for serverTL in unlinkClient #809

Open keithchew opened 3 months ago

keithchew commented 3 months ago

Testing on v6.3.4, got this crash:

------ STACK TRACE ------
EIP:
/opt/KeyDB/bin/keydb-server *:6379(unlinkClient(client*)+0x345) [0x563dfad38505]

Backtrace:
/lib/x86_64-linux-gnu/libpthread.so.0(+0x14420) [0x7fc8299f8420]
/opt/KeyDB/bin/keydb-server *:6379(unlinkClient(client*)+0x345) [0x563dfad38505]
/opt/KeyDB/bin/keydb-server *:6379(freeClient(client*)+0x3f1) [0x563dfad39071]
/opt/KeyDB/bin/keydb-server *:6379(RM_FreeThreadSafeContext(RedisModuleCtx*)+0x78) [0x563dfae05818]

I traced this and unlinkClient() in networking.cpp has a line which assumes serverTL is available, but it is not. The fix is a simple one:

...
    if (serverTL) {
        serverTL->vecclientsProcess.erase(std::remove(serverTL->vecclientsProcess.begin(), serverTL->vecclientsProcess.end(), c), serverTL->vecclientsProcess.end());
...