diff options
author | Guilherme G. Menaldo <guilherme.menaldo@outlook.com> | 2018-03-01 02:12:57 -0300 |
---|---|---|
committer | Guilherme G. Menaldo <guilherme.menaldo@outlook.com> | 2018-03-08 23:14:22 -0300 |
commit | c071cb6e4ab5eaac34e5cc2d54d8d0a441e8ea24 (patch) | |
tree | 6f19b0e13e7046599f0b54dd23715020d21119ce | |
parent | 5b4f79ade2152da83e3c5df610efd54714acaa1f (diff) | |
download | hercules-c071cb6e4ab5eaac34e5cc2d54d8d0a441e8ea24.tar.gz hercules-c071cb6e4ab5eaac34e5cc2d54d8d0a441e8ea24.tar.bz2 hercules-c071cb6e4ab5eaac34e5cc2d54d8d0a441e8ea24.tar.xz hercules-c071cb6e4ab5eaac34e5cc2d54d8d0a441e8ea24.zip |
Fixed a nullpo error when user tried to do an action in an unloaded mail in rodex
-rw-r--r-- | src/char/int_rodex.c | 14 | ||||
-rw-r--r-- | src/char/mapif.c | 2 | ||||
-rw-r--r-- | src/char/mapif.h | 2 | ||||
-rw-r--r-- | src/map/clif.c | 14 | ||||
-rw-r--r-- | src/map/clif.h | 2 | ||||
-rw-r--r-- | src/map/intif.c | 11 |
6 files changed, 28 insertions, 17 deletions
diff --git a/src/char/int_rodex.c b/src/char/int_rodex.c index 127f7a213..2001ddc43 100644 --- a/src/char/int_rodex.c +++ b/src/char/int_rodex.c @@ -349,22 +349,23 @@ int64 inter_rodex_savemessage(struct rodex_message* msg) /*========================================== * Inbox Request *------------------------------------------*/ -void mapif_rodex_sendinbox(int fd, int char_id, int8 opentype, int8 flag, int count, struct rodex_maillist *mails) +void mapif_rodex_sendinbox(int fd, int char_id, int8 opentype, int8 flag, int count, int64 mail_id, struct rodex_maillist *mails) { - int per_packet = (UINT16_MAX - 16) / sizeof(struct rodex_message); + int per_packet = (UINT16_MAX - 24) / sizeof(struct rodex_message); int sent = 0; bool is_first = true; nullpo_retv(mails); Assert_retv(char_id > 0); Assert_retv(count >= 0); + Assert_retv(mail_id >= 0); do { - int i = 16, j, size, limit; + int i = 24, j, size, limit; int to_send = count - sent; bool is_last = true; if (to_send <= per_packet) { - size = to_send * sizeof(struct rodex_message) + 16; + size = to_send * sizeof(struct rodex_message) + 24; limit = to_send; is_last = true; } else { @@ -372,7 +373,7 @@ void mapif_rodex_sendinbox(int fd, int char_id, int8 opentype, int8 flag, int co if (limit != to_send) { is_last = false; } - size = limit * sizeof(struct rodex_message) + 16; + size = limit * sizeof(struct rodex_message) + 24; } WFIFOHEAD(fd, size); @@ -384,6 +385,7 @@ void mapif_rodex_sendinbox(int fd, int char_id, int8 opentype, int8 flag, int co WFIFOB(fd, 10) = is_last; WFIFOB(fd, 11) = is_first; WFIFOL(fd, 12) = limit; + WFIFOQ(fd, 16) = mail_id; for (j = 0; j < limit; ++j, ++sent, i += sizeof(struct rodex_message)) { memcpy(WFIFOP(fd, i), &VECTOR_INDEX(*mails, sent), sizeof(struct rodex_message)); } @@ -408,7 +410,7 @@ void mapif_parse_rodex_requestinbox(int fd) count = inter_rodex->fromsql(char_id, account_id, opentype, 0, &mails); else count = inter_rodex->fromsql(char_id, account_id, opentype, mail_id, &mails); - mapif->rodex_sendinbox(fd, char_id, opentype, flag, count, &mails); + mapif->rodex_sendinbox(fd, char_id, opentype, flag, count, mail_id, &mails); VECTOR_CLEAR(mails); } diff --git a/src/char/mapif.c b/src/char/mapif.c index 241edc925..f80e38fe7 100644 --- a/src/char/mapif.c +++ b/src/char/mapif.c @@ -185,7 +185,7 @@ void mapif_send_quests(int fd, int char_id, struct quest *tmp_questlog, int num_ int mapif_parse_quest_load(int fd); /* RoDEX */ int mapif_parse_rodex_requestinbox(int fd); -void mapif_rodex_sendinbox(int fd, int char_id, int8 opentype, int8 flag, int count, struct rodex_maillist *mails); +void mapif_rodex_sendinbox(int fd, int char_id, int8 opentype, int8 flag, int count, int64 mail_id, struct rodex_maillist *mails); int mapif_parse_rodex_checkhasnew(int fd); void mapif_rodex_sendhasnew(int fd, int char_id, bool has_new); int mapif_parse_rodex_updatemail(int fd); diff --git a/src/char/mapif.h b/src/char/mapif.h index f03f1ad9a..7fc79f661 100644 --- a/src/char/mapif.h +++ b/src/char/mapif.h @@ -177,7 +177,7 @@ struct mapif_interface { void (*send_quests) (int fd, int char_id, struct quest *tmp_questlog, int num_quests); int (*parse_quest_load) (int fd); int(*parse_rodex_requestinbox) (int fd); - void(*rodex_sendinbox) (int fd, int char_id, int8 opentype, int8 flag, int count, struct rodex_maillist *mails); + void(*rodex_sendinbox) (int fd, int char_id, int8 opentype, int8 flag, int count, int64 mail_id, struct rodex_maillist *mails); int(*parse_rodex_checkhasnew) (int fd); void(*rodex_sendhasnew) (int fd, int char_id, bool has_new); int(*parse_rodex_updatemail) (int fd); diff --git a/src/map/clif.c b/src/map/clif.c index 6b444553f..4d883eacb 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -19752,7 +19752,7 @@ void clif_rodex_send_maillist(int fd, struct map_session_data *sd, int8 open_typ #endif } -void clif_rodex_send_mails_all(int fd, struct map_session_data *sd) +void clif_rodex_send_mails_all(int fd, struct map_session_data *sd, int64 mail_id) { #if PACKETVER >= 20170419 struct PACKET_ZC_MAIL_LIST *packet; @@ -19760,18 +19760,24 @@ void clif_rodex_send_mails_all(int fd, struct map_session_data *sd) int16 size = sizeof(*packet); int packetMailCount = 0; int mailListCount = 0; - int mailsSize = VECTOR_LENGTH(sd->rodex.messages); - int i; + int mailsSize, i; + int j = -1; nullpo_retv(sd); + mailsSize = VECTOR_LENGTH(sd->rodex.messages); + + if (mail_id > 0) + ARR_FIND(0, VECTOR_LENGTH(sd->rodex.messages), j, (VECTOR_INDEX(sd->rodex.messages, j)).id == mail_id); + WFIFOHEAD(fd, sizeof(*packet) + (sizeof(*inner) + RODEX_TITLE_LENGTH) * RODEX_MAIL_PER_PAGE); packet = WFIFOP(fd, 0); packet->PacketType = rodexmailList; inner = WFIFOP(fd, size); i = mailsSize - 1; - while (i >= 0) { + mailsSize -= (j + 1); + while (i > j) { struct rodex_message *msg = &VECTOR_INDEX(sd->rodex.messages, i); --i; diff --git a/src/map/clif.h b/src/map/clif.h index 0711546df..acf79c373 100644 --- a/src/map/clif.h +++ b/src/map/clif.h @@ -1389,7 +1389,7 @@ struct clif_interface { void (*rodex_send_mail_result) (int fd, struct map_session_data *sd, int8 result); void (*rodex_send_maillist) (int fd, struct map_session_data *sd, int8 open_type, int64 page_start); void (*rodex_send_refresh) (int fd, struct map_session_data *sd, int8 open_type, int count); - void (*rodex_send_mails_all) (int fd, struct map_session_data *sd); + void (*rodex_send_mails_all) (int fd, struct map_session_data *sd, int64 mail_id); void (*pRodexReadMail) (int fd, struct map_session_data *sd); void (*rodex_read_mail) (struct map_session_data *sd, int8 opentype, struct rodex_message *msg); void (*pRodexNextMaillist) (int fd, struct map_session_data *sd); diff --git a/src/map/intif.c b/src/map/intif.c index b8a0be37c..f656a0df9 100644 --- a/src/map/intif.c +++ b/src/map/intif.c @@ -2516,6 +2516,9 @@ void intif_parse_RequestRodexOpenInbox(int fd) int8 is_end = RFIFOB(fd, 10); int is_first = RFIFOB(fd, 11); int count = RFIFOL(fd, 12); +#if PACKETVER >= 20170419 + int64 mail_id = RFIFOQ(fd, 16); +#endif int i, j; sd = map->charid2sd(RFIFOL(fd, 4)); @@ -2533,15 +2536,15 @@ void intif_parse_RequestRodexOpenInbox(int fd) else sd->rodex.total += count; - if (RFIFOW(fd, 2) - 16 != count * sizeof(struct rodex_message)) { - ShowError("intif_parse_RodexInboxOpenReceived: data size mismatch %d != %"PRIuS"\n", RFIFOW(fd, 2) - 16, count * sizeof(struct rodex_message)); + if (RFIFOW(fd, 2) - 24 != count * sizeof(struct rodex_message)) { + ShowError("intif_parse_RodexInboxOpenReceived: data size mismatch %d != %"PRIuS"\n", RFIFOW(fd, 2) - 24, count * sizeof(struct rodex_message)); return; } if (flag == 0 && is_first) VECTOR_CLEAR(sd->rodex.messages); - for (i = 0, j = 16; i < count; ++i, j += sizeof(struct rodex_message)) { + for (i = 0, j = 24; i < count; ++i, j += sizeof(struct rodex_message)) { struct rodex_message msg = { 0 }; VECTOR_ENSURE(sd->rodex.messages, 1, 1); memcpy(&msg, RFIFOP(fd, j), sizeof(struct rodex_message)); @@ -2550,7 +2553,7 @@ void intif_parse_RequestRodexOpenInbox(int fd) if (is_end == true) { #if PACKETVER >= 20170419 - clif->rodex_send_mails_all(sd->fd, sd); + clif->rodex_send_mails_all(sd->fd, sd, mail_id); #else if (flag == 0) clif->rodex_send_maillist(sd->fd, sd, opentype, VECTOR_LENGTH(sd->rodex.messages) - 1); |