java-topology/defects/minetest-0005/patch/minetest-0005.patch
russell@unturf.com a86a765544 minetest (Luanti): 5 CWE-407 defects, all 5 MOADs scanned
minetest-0001: mg_ore.cpp c_wherein vector CONTAINS in voxel inner loop O(V*W) HIGH 3.3x
minetest-0002: mg_decoration.cpp c_place_on/c_spawnby vector CONTAINS O(S*P) MEDIUM 1.8x
minetest-0003: l_env.cpp find_node_near/find_nodes_in_area filter CONTAINS O(V*F) MEDIUM 1.6x
minetest-0004: nodedef.cpp nodeboxConnects sorted vector linear scan O(N) MEDIUM 2.1x
minetest-0005: blockmodifier.cpp ABM neighbor check sorted vector O(N) LOW-MEDIUM 1.5x

MOAD-0002: g_settings global singleton (architectural, not patchable)
MOAD-0003: thread_local log streams (properly scoped, not leaked context)
MOAD-0004: CLEAN (no credential logging found)
MOAD-0005: CLEAN (no unsynchronized cache patterns found)
2026-03-31 10:10:03 -04:00

23 lines
885 B
Diff

# UNDF: UNDF-2026-000000947
--- a/src/server/blockmodifier.cpp
+++ b/src/server/blockmodifier.cpp
@@ -218,11 +218,13 @@ void ABMHandler::apply(MapBlock *block, ...)
c = n.getContent();
}
+ // required_neighbors and without_neighbors are SORT_AND_UNIQUE'd,
+ // use binary_search O(log N) instead of CONTAINS/std::find O(N)
if (check_required_neighbors && !have_required) {
- if (CONTAINS(aabm.required_neighbors, c)) {
+ if (std::binary_search(aabm.required_neighbors.begin(),
+ aabm.required_neighbors.end(), c)) {
if (!check_without_neighbors)
goto neighbor_found;
have_required = true;
}
}
if (check_without_neighbors) {
- if (CONTAINS(aabm.without_neighbors, c))
+ if (std::binary_search(aabm.without_neighbors.begin(),
+ aabm.without_neighbors.end(), c))
goto neighbor_invalid;
}