diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-02-24 21:46:27 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-02-24 21:46:27 +0300 |
commit | e2fec6a64a403df523d64540f70c73b99fbf491c (patch) | |
tree | 34ee4d272252990071bd84cff303b956e4b57c21 | |
parent | cf9c4ca35fefcf392269179785371b679689364c (diff) | |
download | plugin-e2fec6a64a403df523d64540f70c73b99fbf491c.tar.gz plugin-e2fec6a64a403df523d64540f70c73b99fbf491c.tar.bz2 plugin-e2fec6a64a403df523d64540f70c73b99fbf491c.tar.xz plugin-e2fec6a64a403df523d64540f70c73b99fbf491c.zip |
map: add missing checks.
-rw-r--r-- | src/map/clif.c | 35 | ||||
-rw-r--r-- | src/map/itemdb.c | 2 | ||||
-rw-r--r-- | src/map/map.c | 11 | ||||
-rw-r--r-- | src/map/parse.c | 4 | ||||
-rw-r--r-- | src/map/pc.c | 6 | ||||
-rw-r--r-- | src/map/script.c | 19 | ||||
-rw-r--r-- | src/map/send.c | 21 | ||||
-rw-r--r-- | src/map/unit.c | 5 |
8 files changed, 86 insertions, 17 deletions
diff --git a/src/map/clif.c b/src/map/clif.c index e0e2cf6..6099dd5 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -25,6 +25,12 @@ void eclif_quest_send_list(struct map_session_data *sd) { + if (!sd) + { + hookStop(); + return; + } + int fd = sd->fd; int i; int info_len = 15; @@ -37,6 +43,8 @@ void eclif_quest_send_list(struct map_session_data *sd) for (i = 0; i < sd->avail_quests; i++ ) { struct quest_db *qi = quest->db(sd->quest_log[i].quest_id); + if (!qi) + continue; WFIFOL(fd, i * info_len + 8) = sd->quest_log[i].quest_id; WFIFOB(fd, i * info_len + 12) = sd->quest_log[i].count[0]; // was state WFIFOL(fd, i * info_len + 13) = sd->quest_log[i].time - qi->time; @@ -50,9 +58,20 @@ void eclif_quest_send_list(struct map_session_data *sd) void eclif_quest_add(struct map_session_data *sd, struct quest *qd) { + if (!sd) + { + hookStop(); + return; + } int fd = sd->fd; struct quest_db *qi = quest->db(qd->quest_id); + if (!qi) + { + hookStop(); + return; + } + WFIFOHEAD(fd, packet_len(0x2b3)); WFIFOW(fd, 0) = 0x2b3; WFIFOL(fd, 2) = qd->quest_id; @@ -76,6 +95,11 @@ void eclif_charnameack(int *fdPtr, struct block_list *bl) { int fd = *fdPtr; struct map_session_data* sd = (struct map_session_data*)session[fd]->session_data; + if (!sd) + { + hookStop(); + return; + } const char *tr = lang_pctrans(((TBL_NPC*)bl)->name, sd); const int trLen = strlen(tr); const int len = 8 + trLen; @@ -115,13 +139,16 @@ void eclif_charnameack(int *fdPtr, struct block_list *bl) static void eclif_send_additional_slots(struct map_session_data* sd, struct map_session_data* sd2) { + if (!sd || !sd2) + return; + const int id = sd->bl.id; const int fd = sd2->fd; struct item_data *item; short equip; struct MapdExt *data = mapd_get(sd->bl.m); - if (data->invisible) + if (!data || data->invisible) return; equipPos(EQI_HEAD_LOW, LOOK_HEAD_BOTTOM); @@ -139,6 +166,8 @@ static void eclif_send_additional_slots(struct map_session_data* sd, struct map_ void eclif_getareachar_unit_post(struct map_session_data* sd, struct block_list *bl) { + if (!bl) + return; if (bl->type == BL_PC) { eclif_send_additional_slots(sd, (struct map_session_data *)bl); @@ -161,6 +190,8 @@ void eclif_authok_post(struct map_session_data *sd) void eclif_changemap_post(struct map_session_data *sd, short *m, int *x __attribute__ ((unused)), int *y __attribute__ ((unused))) { + if (!sd) + return; struct MapdExt *data = mapd_get(*m); int mask = data ? data->mask : 1; send_mapmask(sd->fd, mask); @@ -171,7 +202,7 @@ void eclif_handle_invisible_map(struct block_list *bl, enum send_target target _ if (!bl || bl->type != BL_PC) return; struct MapdExt *data = mapd_get(bl->m); - if (data->invisible) + if (data && data->invisible) hookStop(); } diff --git a/src/map/itemdb.c b/src/map/itemdb.c index cccabc5..6fb9f02 100644 --- a/src/map/itemdb.c +++ b/src/map/itemdb.c @@ -22,6 +22,8 @@ bool eitemdb_is_item_usable(struct item_data *item) { hookStop(); + if (!item) + return false; return item->type == IT_HEALING || item->type == IT_USABLE || item->type == IT_CASH || item->type == IT_PETEGG; } diff --git a/src/map/map.c b/src/map/map.c index ec7483b..6567337 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -36,7 +36,7 @@ int emap_addflooritem_post(int retVal, int *flags __attribute__ ((unused))) { struct flooritem_data* fitem = (struct flooritem_data*)idb_get(map->id_db, retVal); - if (fitem->cleartimer != INVALID_TIMER) + if (fitem && fitem->cleartimer != INVALID_TIMER) { int timeout = battle->bc->flooritem_lifetime; struct ItemdExt *data = itemd_get_by_item(item); @@ -56,6 +56,9 @@ void emap_online_list(int fd) struct map_session_data* sd; struct SessionExt *data1 = session_get(fd); + if (!data1) + return; + const time_t t = time(NULL); if (data1->onlinelistlasttime + 15 >= t) { // not more than 1 per 15 seconds @@ -64,6 +67,9 @@ void emap_online_list(int fd) } struct map_session_data* ssd = (struct map_session_data*)session[fd]->session_data; + if (!ssd) + return; + const bool showVersion = pc_has_permission(ssd, permission_show_client_version_flag); data1->onlinelistlasttime = t; @@ -78,6 +84,9 @@ void emap_online_list(int fd) break; struct SessionExt *data = session_get_bysd(sd); + if (!data) + continue; + // need skip invisible players uint8 state = data->state; diff --git a/src/map/parse.c b/src/map/parse.c index b06828c..97aac6f 100644 --- a/src/map/parse.c +++ b/src/map/parse.c @@ -25,6 +25,8 @@ void map_parse_version(int fd) { struct SessionExt *data = session_get(fd); + if (!data) + return; data->clientVersion = RFIFOL(fd, 2); } @@ -134,6 +136,8 @@ void map_parse_pet_emote(int fd) void map_parse_set_status(int fd) { struct SessionExt *data = session_get(fd); + if (!data) + return; data->state = RFIFOB(fd, 2); } diff --git a/src/map/pc.c b/src/map/pc.c index 612393f..b4de8c4 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -75,6 +75,9 @@ void epc_equipitem_pos(struct map_session_data *sd, struct item_data *id, int *p { int pos = *posPtr; + if (!id) + return; + equipPos(EQP_HEAD_LOW, head_bottom, LOOK_HEAD_BOTTOM); equipPos(EQP_HEAD_TOP, head_top, LOOK_HEAD_TOP); equipPos(EQP_HEAD_MID, head_mid, LOOK_HEAD_MID); @@ -111,6 +114,9 @@ void epc_unequipitem_pos(struct map_session_data *sd, int *nPtr __attribute__ ((unused)), int *posPtr) { + if (!sd) + return; + int pos = *posPtr; unequipPos(EQP_HEAD_LOW, head_bottom, LOOK_HEAD_BOTTOM); diff --git a/src/map/script.c b/src/map/script.c index 8c8f946..8017ed1 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -139,10 +139,24 @@ BUILDIN(npcTalk3) return false; } + if (!str) + { + ShowWarning("error in string\n"); + script->reportsrc(st); + return false; + } + if (sd) msg = (char*)lang_pctrans (nd->name, sd); else msg = nd->name; + + if (!msg) + { + ShowWarning("error in string\n"); + script->reportsrc(st); + return false; + } if (strlen(str) + strlen(msg) > 450) { ShowWarning("text message too big\n"); @@ -273,9 +287,7 @@ BUILDIN(requestLang) int lng = -1; if (*sd->npc_str) - { lng = lang_getId(sd->npc_str); - } script->set_reg(st, sd, uid, name, (void*)h64BPTRSIZE(lng), script_getref(st,2)); st->state = RUN; } @@ -934,6 +946,9 @@ BUILDIN(areaTimer) static int buildin_getareadropitem_sub_del(struct block_list *bl, va_list ap) { + if (!bl) + return 0; + const int item = va_arg(ap, int); int *const amount = va_arg(ap, int *); struct flooritem_data *drop = (struct flooritem_data *)bl; diff --git a/src/map/send.c b/src/map/send.c index 6503719..61522ac 100644 --- a/src/map/send.c +++ b/src/map/send.c @@ -57,10 +57,10 @@ void send_npccommand2 (struct map_session_data *sd, int npcId, int cmd, int id, void send_local_message(int fd, struct block_list* bl, const char* msg) { + if (!msg || !bl) + return; unsigned short msg_len = strlen(msg) + 1; uint8 buf[256]; - if (!bl) - return; int len = sizeof(buf) - 8; if (msg_len > len) @@ -112,11 +112,10 @@ void send_mapmask_brodcast(const int map, const int mask) void send_mob_info(struct block_list* bl1, struct block_list* bl2, enum send_target target) { - char buf[12]; - - if (bl1->type != BL_MOB) + if (!bl1 || bl1->type != BL_MOB) return; + char buf[12]; struct mob_data *md = (struct mob_data *)bl1; WBUFW (buf, 0) = 0xb03; @@ -131,11 +130,10 @@ void send_pc_info(struct block_list* bl1, struct block_list* bl2, enum send_target target) { - char buf[12]; - - if (bl1->type != BL_PC) + if (!bl1 || bl1->type != BL_PC) return; + char buf[12]; struct map_session_data *sd = (struct map_session_data *)bl1; struct SessionExt *data = session_get_bysd(sd); if (!data) @@ -253,6 +251,9 @@ void send_changenpc_title (struct map_session_data *sd, const int npcId, const c void send_join_ack(int fd, const char *const name, int flag) { + if (!name) + return; + WFIFOHEAD (fd, 27); WFIFOW (fd, 0) = 0xb08; safestrncpy ((char*)WFIFOP (fd, 2), name, 24); @@ -262,7 +263,7 @@ void send_join_ack(int fd, const char *const name, int flag) void send_pet_say(struct map_session_data *sd, const char *const message) { - if (!sd || !sd->pd) + if (!sd || !sd->pd || !message) return; const char *const name = sd->pd->pet.name; @@ -286,6 +287,8 @@ void send_pet_emote(struct map_session_data *sd, const int emote) void send_online_list(int fd, const char *buf, unsigned size) { + if (!buf) + return; const unsigned int len = size + 4 + 1; WFIFOHEAD (fd, len); WFIFOW (fd, 0) = 0xb10; diff --git a/src/map/unit.c b/src/map/unit.c index 01dedc2..5a1ca83 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -26,7 +26,6 @@ int eunit_can_move(struct block_list *bl) struct unit_data *ud; struct status_change *sc; - if (!bl) { hookStop(); @@ -136,9 +135,9 @@ int eunit_can_move(struct block_list *bl) if(md && ((md->status.mode&MD_BOSS && battle->bc->boss_icewall_walk_block == 1 && map->getcell(bl->m,bl->x,bl->y,CELL_CHKICEWALL)) || (!(md->status.mode&MD_BOSS) && battle->bc->mob_icewall_walk_block == 1 && map->getcell(bl->m,bl->x,bl->y,CELL_CHKICEWALL)))) { - md->walktoxy_fail_count = 1; //Make sure rudeattacked skills are invoked + md->walktoxy_fail_count = 1; //Make sure rudeattacked skills are invoked hookStop(); - return 0; + return 0; } } |