summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorIbrahim Zidan <brahem@aotsw.com>2020-04-04 02:48:42 +0200
committerIbrahim Zidan <brahem@aotsw.com>2020-04-05 20:03:27 +0200
commit58c4ce73b9fdc1d67a928e37742510bf49bb7dbc (patch)
tree8d0b1b1d871a634b3f71f0c082bca00061f99884 /src/map
parentf9f72c9d4a8c46587d06ba7c95c07d889be2c803 (diff)
downloadhercules-58c4ce73b9fdc1d67a928e37742510bf49bb7dbc.tar.gz
hercules-58c4ce73b9fdc1d67a928e37742510bf49bb7dbc.tar.bz2
hercules-58c4ce73b9fdc1d67a928e37742510bf49bb7dbc.tar.xz
hercules-58c4ce73b9fdc1d67a928e37742510bf49bb7dbc.zip
Fixed a memory violation in quest info caused by accessing -1 index when qi_list vector length is 0
Signed-off-by: Ibrahim Zidan <brahem@aotsw.com>
Diffstat (limited to 'src/map')
-rw-r--r--src/map/map.c6
-rw-r--r--src/map/script.c5
2 files changed, 8 insertions, 3 deletions
diff --git a/src/map/map.c b/src/map/map.c
index 6ebc50ba3..b2c9c77c3 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -6047,8 +6047,12 @@ static bool map_add_questinfo(int m, struct npc_data *nd)
nullpo_retr(false, nd);
Assert_retr(false, m >= 0 && m < map->count);
- if (VECTOR_LAST(map->list[m].qi_list) == nd)
+ int i;
+ ARR_FIND(0, VECTOR_LENGTH(map->list[m].qi_list), i, VECTOR_INDEX(map->list[m].qi_list, i) == nd);
+
+ if (i < VECTOR_LENGTH(map->list[m].qi_list)) {
return false;
+ }
VECTOR_ENSURE(map->list[m].qi_list, 1, 1);
VECTOR_PUSH(map->list[m].qi_list, nd);
diff --git a/src/map/script.c b/src/map/script.c
index b8a7979a7..9a2b0f757 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -22021,12 +22021,13 @@ static BUILDIN(setquestinfo)
return false;
}
- qi = &VECTOR_LAST(nd->qi_data);
- if (qi == NULL) {
+ if (VECTOR_LENGTH(nd->qi_data) == 0) {
ShowWarning("buildin_setquestinfo: no valide questinfo data has been found for this npc.\n");
return false;
}
+ qi = &VECTOR_LAST(nd->qi_data);
+
switch (type) {
case QINFO_JOB:
{