From a5e46e28443c7ca5b23f1f49c25e2427df9dcbb5 Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Tue, 24 Oct 2023 02:26:55 -0700 Subject: [PATCH] Chat: Fix possible nullptr access (#1238) Fixes a possible nullptr access. This is the only call to GetPlayerData where we do not check the result for some reason, so this PR adds in the check and a resulting log line. Code compiles, unsure how to reproduce the issue, however here is the crash dump I used to deduce this being the possible issue ``` Error: signal 11: [00] CatchUnhandled(int)(+0x316) [0x561469100336] [01] /lib/x86_64-linux-gnu/libc.so.6(+0x42520) [0x7f65e8e45520] [02] /DarkflameServer/build/ChatServer(+0x32719) [0x5614690fa719] [03] HandlePacket(Packet*)(+0x2a0) [0x5614690fcfb0] [04] /DarkflameServer/build/ChatServer(main+0x92e) [0x5614690fb75e] [05] /lib/x86_64-linux-gnu/libc.so.6(+0x29d90) [0x7f65e8e2cd90] [06] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80) [0x7f65e8e2ce40] [07] /DarkflameServer/build/ChatServer(_start+0x25) [0x5614690fc375] ``` --- dChatServer/ChatPacketHandler.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dChatServer/ChatPacketHandler.cpp b/dChatServer/ChatPacketHandler.cpp index c6cc24b1..72383c38 100644 --- a/dChatServer/ChatPacketHandler.cpp +++ b/dChatServer/ChatPacketHandler.cpp @@ -118,6 +118,11 @@ void ChatPacketHandler::HandleFriendRequest(Packet* packet) { inStream.Read(isBestFriendRequest); auto requestor = playerContainer.GetPlayerData(requestorPlayerID); + if (!requestor) { + LOG("No requestor player %llu sent to %s found.", requestorPlayerID, playerName.c_str()); + return; + } + if (requestor->playerName == playerName) { SendFriendResponse(requestor, requestor, eAddFriendResponseType::MYTHRAN); return;