Skip to content

Commit eea488e

Browse files
SmallJokerThomas--S
andauthoredAug 23, 2021
Inventory: Fix rare out-of-bounds access
Co-authored-by: Thomas--S <info@thomas-stangl.de>
1 parent dad87a3 commit eea488e

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed
 

Diff for: ‎src/inventorymanager.cpp

+12-4
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
273273
}
274274
if (!list_to) {
275275
infostream << "IMoveAction::apply(): FAIL: destination list not found: "
276-
<< "to_inv=\""<<to_inv.dump() << "\""
276+
<< "to_inv=\"" << to_inv.dump() << "\""
277277
<< ", to_list=\"" << to_list << "\"" << std::endl;
278278
return;
279279
}
@@ -322,12 +322,20 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
322322
return;
323323
}
324324

325-
if ((u16)to_i > list_to->getSize()) {
325+
if (from_i < 0 || list_from->getSize() <= (u32) from_i) {
326+
infostream << "IMoveAction::apply(): FAIL: source index out of bounds: "
327+
<< "size of from_list=\"" << list_from->getSize() << "\""
328+
<< ", from_index=\"" << from_i << "\"" << std::endl;
329+
return;
330+
}
331+
332+
if (to_i < 0 || list_to->getSize() <= (u32) to_i) {
326333
infostream << "IMoveAction::apply(): FAIL: destination index out of bounds: "
327-
<< "to_i=" << to_i
328-
<< ", size=" << list_to->getSize() << std::endl;
334+
<< "size of to_list=\"" << list_to->getSize() << "\""
335+
<< ", to_index=\"" << to_i << "\"" << std::endl;
329336
return;
330337
}
338+
331339
/*
332340
Do not handle rollback if both inventories are that of the same player
333341
*/

0 commit comments

Comments
 (0)
Please sign in to comment.