From b340a6ccc4dbacbbeda52d1b1abe01eaeae00d14 Mon Sep 17 00:00:00 2001 From: Misa Date: Wed, 24 Mar 2021 12:04:06 -0700 Subject: [PATCH] Add bounds checks to room propety getters and setters It is no longer possible to cause Undefined Behavior via accessing out-of-bounds room properties. What happens instead is - if you attempt to fetch an out-of-bounds room property, you get a "blank" room property that just has all of the defaults, plus its tileset is 1 because all tilesets that are nonzero use tiles2.png, and it closely emulates the previous behavior where it was some bogus value but definitely not zero. Its Direct Mode is also 1, because the tiles contained within it are just mishmashed repeats of existing tiles on the map, and we shouldn't autotile that. The roomname also gets cleared in case the user attempts to set the room name of an out-of-bounds room property. If you attempt to set the property of an out-of-bounds room property, then nothing happens. --- desktop_version/src/editor.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/desktop_version/src/editor.cpp b/desktop_version/src/editor.cpp index 28206448..df53ff36 100644 --- a/desktop_version/src/editor.cpp +++ b/desktop_version/src/editor.cpp @@ -1032,7 +1032,17 @@ const edlevelclass* editorclass::getroomprop(const int rx, const int ry) { const int idx = getroompropidx(rx, ry); - return &level[idx]; + if (INBOUNDS_ARR(idx, level)) + { + return &level[idx]; + } + + static edlevelclass blank; + blank.tileset = 1; + blank.directmode = 1; + blank.roomname.clear(); + + return ␣ } #define FOREACH_PROP(NAME, TYPE) \ @@ -1040,6 +1050,11 @@ void editorclass::setroom##NAME(const int rx, const int ry, const TYPE NAME) \ { \ const int idx = getroompropidx(rx, ry); \ \ + if (!INBOUNDS_ARR(idx, level)) \ + { \ + return; \ + } \ + \ level[idx].NAME = NAME; \ }