Skip to content

Commit d3bf0f5

Browse files
committed
Fixed heap-buffer-overflow on npcshopdelitem
npcshopdelitem now moves data within structure size.
1 parent 852c133 commit d3bf0f5

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/map/script.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18030,10 +18030,12 @@ static BUILDIN(npcshopdelitem)
1803018030
unsigned int nameid = script_getnum(st,i);
1803118031

1803218032
ARR_FIND(0, size, n, nd->u.shop.shop_item[n].nameid == nameid);
18033-
if (n < size) {
18034-
memmove(&nd->u.shop.shop_item[n], &nd->u.shop.shop_item[n+1], sizeof(nd->u.shop.shop_item[0])*(size-n));
18035-
size--;
18033+
if (n == size) {
18034+
continue;
18035+
} else if (n < size - 1) {
18036+
memmove(&nd->u.shop.shop_item[n], &nd->u.shop.shop_item[n+1], sizeof(nd->u.shop.shop_item[0]) * (size - n - 1));
1803618037
}
18038+
size--;
1803718039
}
1803818040

1803918041
RECREATE(nd->u.shop.shop_item, struct npc_item_list, size);

0 commit comments

Comments
 (0)