From 68f8a4bc7f80b8a147a41b263f0a90ddfe193ddf Mon Sep 17 00:00:00 2001 From: Lemongrass3110 Date: Mon, 17 Jun 2024 18:30:43 +0200 Subject: [PATCH] Fixed a crash with unknown packets (#8437) Fixes #8432 Thanks to @gmragnarok --- src/char/char_clif.cpp | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/char/char_clif.cpp b/src/char/char_clif.cpp index 9e5c876057..c218291179 100644 --- a/src/char/char_clif.cpp +++ b/src/char/char_clif.cpp @@ -1594,19 +1594,27 @@ int chclif_parse(int fd) { // Before processing any other packets, do a few checks default: - // If the pincode was entered correctly - if( sd->pincode_correct ){ - break; - } + // To reach this block the client should have attained a session already + if( sd != nullptr ){ + // If the pincode was entered correctly + if( sd->pincode_correct ){ + break; + } - // If no pincode is set (yet) - if( strlen( sd->pincode ) <= 0 ){ - break; - } + // If no pincode is set (yet) + if( strlen( sd->pincode ) <= 0 ){ + break; + } - // The pincode was not entered correctly, yet the player (=bot) tried to send a different packet => Goodbye! - set_eof( fd ); - return 0; + // The pincode was not entered correctly, yet the player (=bot) tried to send a different packet => Goodbye! + set_eof( fd ); + return 0; + }else{ + // Unknown packet received + ShowError( "chclif_parse: Received unknown packet " CL_WHITE "0x%x" CL_RESET " from ip '" CL_WHITE "%s" CL_RESET "'! Disconnecting!\n", cmd, ip2str( ipl, nullptr ) ); + set_eof( fd ); + return 0; + } } } #endif @@ -1654,7 +1662,7 @@ int chclif_parse(int fd) { break; // unknown packet received default: - ShowError("parse_char: Received unknown packet " CL_WHITE "0x%x" CL_RESET " from ip '" CL_WHITE "%s" CL_RESET "'! Disconnecting!\n", RFIFOW(fd,0), ip2str(ipl, nullptr)); + ShowError( "chclif_parse: Received unknown packet " CL_WHITE "0x%x" CL_RESET " from ip '" CL_WHITE "%s" CL_RESET "'! Disconnecting!\n", cmd, ip2str( ipl, nullptr ) ); set_eof(fd); return 0; }