Pārlūkot izejas kodu

Fixed a crash with unknown packets (#8437)

Fixes #8432

Thanks to @gmragnarok
Lemongrass3110 11 mēneši atpakaļ
vecāks
revīzija
68f8a4bc7f
1 mainītis faili ar 21 papildinājumiem un 13 dzēšanām
  1. 21 13
      src/char/char_clif.cpp

+ 21 - 13
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;
+						}
+
+						// 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;
 					}
-
-					// 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;
 			}
 		}
 #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;
 		}