From 67df8a9679aeae3afad5c6597ceca0d1a47722ab Mon Sep 17 00:00:00 2001 From: Misa Date: Tue, 9 Jan 2024 23:57:14 -0800 Subject: [PATCH] Add bounds check to textcase() command This makes it so that only inputs between 1 and 255 inclusive will be accepted. Otherwise, the command has no effect. This is because the text case is stored as one byte in a string, and a value of zero would be the null terminator. We also want to minimize potential weirdness with integer wrapping if we accept inputs from outside those bounds. While the textcase variable as used throughout the codebase is plain unqualified `char` (which, unlike other integers, exists in a quantum superposition of being signed and unsigned depending on compiler, machine, and various other stuff) and so there still might be issues there, we definitely don't want anything higher than 255. --- desktop_version/src/Script.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/desktop_version/src/Script.cpp b/desktop_version/src/Script.cpp index 6573a924..b4dac088 100644 --- a/desktop_version/src/Script.cpp +++ b/desktop_version/src/Script.cpp @@ -2457,7 +2457,11 @@ void scriptclass::run(void) else if (words[0] == "textcase") { // Used to disambiguate identical textboxes for translations (1 by default) - textcase = ss_toi(words[1]); + const int number = ss_toi(words[1]); + if (number >= 1 && number <= 255) + { + textcase = number; + } } else if (words[0] == "loadtext") {