Skip to content

Commit

Permalink
wzmaplib: Fix boundary check (#4156)
Browse files Browse the repository at this point in the history
  • Loading branch information
aco4 authored Jan 28, 2025
1 parent 22ce2b1 commit a7e3e06
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/wzmaplib/src/map_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ static JSValue runMap_setMapData(JSContext *ctx, JSValueConst this_val, int argc
JS_FreeValue(ctx, yVal);
}
auto direction = QuickJS_GetInt32(ctx, structure, "direction");
SCRIPT_ASSERT_AND_RETURNERROR(ctx, direction >= 0 && direction < static_cast<int32_t>(std::numeric_limits<uint16_t>::max()), "Invalid direction (%d) for structure", direction);
SCRIPT_ASSERT_AND_RETURNERROR(ctx, direction >= 0 && direction <= static_cast<int32_t>(std::numeric_limits<uint16_t>::max()), "Invalid direction (%d) for structure", direction);
sd.direction = static_cast<uint16_t>(direction);
auto modules = QuickJS_GetUint32(ctx, structure, "modules");
SCRIPT_ASSERT_AND_RETURNERROR(ctx, modules < static_cast<uint32_t>(std::numeric_limits<uint8_t>::max()), "Invalid modules (%" PRIu32 ") for structure", modules);
Expand Down Expand Up @@ -367,7 +367,7 @@ static JSValue runMap_setMapData(JSContext *ctx, JSValueConst this_val, int argc
JS_FreeValue(ctx, yVal);
}
auto direction = QuickJS_GetInt32(ctx, droid, "direction");
SCRIPT_ASSERT_AND_RETURNERROR(ctx, direction >= 0 && direction < static_cast<int32_t>(std::numeric_limits<uint16_t>::max()), "Invalid direction (%d) for droid", direction);
SCRIPT_ASSERT_AND_RETURNERROR(ctx, direction >= 0 && direction <= static_cast<int32_t>(std::numeric_limits<uint16_t>::max()), "Invalid direction (%d) for droid", direction);
sd.direction = static_cast<uint16_t>(direction);
auto player = QuickJS_GetInt32(ctx, droid, "player");
SCRIPT_ASSERT_AND_RETURNERROR(ctx, sd.player >= -1 && sd.player < MAX_PLAYERS, "Invalid player (%d) for droid", (int)sd.player);
Expand Down Expand Up @@ -399,7 +399,7 @@ static JSValue runMap_setMapData(JSContext *ctx, JSValueConst this_val, int argc
JS_FreeValue(ctx, yVal);
}
auto direction = QuickJS_GetInt32(ctx, feature, "direction");
SCRIPT_ASSERT_AND_RETURNERROR(ctx, direction >= 0 && direction < static_cast<int32_t>(std::numeric_limits<uint16_t>::max()), "Invalid direction (%d) for feature", direction);
SCRIPT_ASSERT_AND_RETURNERROR(ctx, direction >= 0 && direction <= static_cast<int32_t>(std::numeric_limits<uint16_t>::max()), "Invalid direction (%d) for feature", direction);
sd.direction = static_cast<uint16_t>(direction);
mapFeatures->push_back(std::move(sd));
}
Expand Down

0 comments on commit a7e3e06

Please sign in to comment.