Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix boundary check in script generated maps #4156

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/wzmaplib/src/map_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,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 @@ -360,7 +360,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 @@ -392,7 +392,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
Loading