Skip to content

Commit 14b8bb2

Browse files
CarterLiCopilot
andcommitted
Temps: validates temp color thresholds as integers in JSON parsing
Co-authored-by: Copilot <copilot@github.com>
1 parent b68ad36 commit 14b8bb2

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/common/impl/temps.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,12 @@ bool ffTempsParseJsonObject(yyjson_val* key, yyjson_val* value, bool* useTemp, F
123123

124124
yyjson_val* greenVal = yyjson_obj_get(value, "green");
125125
if (greenVal) {
126-
int num = yyjson_get_int(greenVal);
126+
if (!yyjson_is_int(greenVal)) {
127+
fputs("Error: usage: temp.green must be an integer between 0 and 100\n", stderr);
128+
exit(480);
129+
}
130+
131+
int num = unsafe_yyjson_get_int(greenVal);
127132
if (num < 0 || num > 100) {
128133
fputs("Error: usage: temp.green must be between 0 and 100\n", stderr);
129134
exit(480);
@@ -133,7 +138,12 @@ bool ffTempsParseJsonObject(yyjson_val* key, yyjson_val* value, bool* useTemp, F
133138

134139
yyjson_val* yellowVal = yyjson_obj_get(value, "yellow");
135140
if (yellowVal) {
136-
int num = yyjson_get_int(yellowVal);
141+
if (!yyjson_is_int(yellowVal)) {
142+
fputs("Error: usage: temp.yellow must be an integer between 0 and 100\n", stderr);
143+
exit(480);
144+
}
145+
146+
int num = unsafe_yyjson_get_int(yellowVal);
137147
if (num < 0 || num > 100) {
138148
fputs("Error: usage: temp.yellow must be between 0 and 100\n", stderr);
139149
exit(480);

0 commit comments

Comments
 (0)