Skip to content

Commit d2b2060

Browse files
SuGliderCopilot
andauthored
feat(matter): checks level to verify that it is valid
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 38f04b8 commit d2b2060

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

libraries/Matter/src/MatterEndpoints/MatterTemperatureControlledCabinet.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,19 @@ bool MatterTemperatureControlledCabinet::begin(uint8_t *supportedLevels, uint16_
247247
log_e("Level count %u exceeds maximum %u", levelCount, temperature_control::k_max_temp_level_count);
248248
return false;
249249
}
250-
250+
251+
// Validate that selectedLevel exists in supportedLevels array
252+
bool levelFound = false;
253+
for (uint16_t i = 0; i < levelCount; i++) {
254+
if (supportedLevels[i] == selectedLevel) {
255+
levelFound = true;
256+
break;
257+
}
258+
}
259+
if (!levelFound) {
260+
log_e("Selected level %u is not in the supported levels array", selectedLevel);
261+
return false;
262+
}
251263
return beginInternal(supportedLevels, levelCount, selectedLevel);
252264
}
253265

0 commit comments

Comments
 (0)