Fixes a potential crash with the mail system (#5345)

* Fixes a potential crash with the mail system
* Fixes #5298.
* Resolves a potential crash with the mail system if someone is modifying packets.
* Adds an extra item verification check.
Thanks to @blipblopblip!
This commit is contained in:
Aleos 2020-08-21 16:59:34 -04:00 committed by GitHub
parent ca27c6d89d
commit 229f086b31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16156,7 +16156,7 @@ void clif_parse_Mail_return(int fd, struct map_session_data *sd){
/// 0a04 <index>.W <amount>.W (CZ_REQ_ADD_ITEM_TO_MAIL)
void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
int idx = RFIFOW(fd,info->pos[0]);
uint16 idx = RFIFOW(fd,info->pos[0]);
#if PACKETVER < 20150513
int amount = RFIFOL(fd,info->pos[1]);
#else
@ -16166,7 +16166,10 @@ void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
if( !chrif_isconnected() )
return;
if (idx < 0 || amount < 0 || idx >= MAX_INVENTORY)
if (amount < 0 || server_index(idx) >= MAX_INVENTORY)
return;
if (sd->inventory_data[server_index(idx)] == nullptr)
return;
flag = mail_setitem(sd, idx, amount);