Fixed a crash with unknown packets (#8437)

Fixes #8432

Thanks to @gmragnarok
This commit is contained in:
Lemongrass3110 2024-06-17 18:30:43 +02:00 committed by GitHub
parent 6451925430
commit 68f8a4bc7f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1594,19 +1594,27 @@ int chclif_parse(int fd) {
// Before processing any other packets, do a few checks // Before processing any other packets, do a few checks
default: default:
// If the pincode was entered correctly // To reach this block the client should have attained a session already
if( sd->pincode_correct ){ if( sd != nullptr ){
break; // If the pincode was entered correctly
} if( sd->pincode_correct ){
break;
}
// If no pincode is set (yet) // If no pincode is set (yet)
if( strlen( sd->pincode ) <= 0 ){ if( strlen( sd->pincode ) <= 0 ){
break; break;
} }
// The pincode was not entered correctly, yet the player (=bot) tried to send a different packet => Goodbye! // The pincode was not entered correctly, yet the player (=bot) tried to send a different packet => Goodbye!
set_eof( fd ); set_eof( fd );
return 0; 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 #endif
@ -1654,7 +1662,7 @@ int chclif_parse(int fd) {
break; break;
// unknown packet received // unknown packet received
default: 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); set_eof(fd);
return 0; return 0;
} }