From ec1db378bdd250e94025843fc96bdaa9dcee2f5d Mon Sep 17 00:00:00 2001 From: roynatech2544 Date: Sat, 22 Oct 2022 17:32:33 +0900 Subject: [PATCH] universal7885: fm-aidl: MiddleState: Bounds checking we need at least 2 elements on the vector. If it doesn't meet the requirements, return nullptr to keep it as-is unmodified. --- .../apps/aidl-support/fm/default/MiddleState.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/universal7885-common/apps/aidl-support/fm/default/MiddleState.cpp b/universal7885-common/apps/aidl-support/fm/default/MiddleState.cpp index e78aba7..843d83b 100644 --- a/universal7885-common/apps/aidl-support/fm/default/MiddleState.cpp +++ b/universal7885-common/apps/aidl-support/fm/default/MiddleState.cpp @@ -3,6 +3,12 @@ middlestate_t *saveMiddleState(const int value, const std::vector &vec) { unsigned int i; + + // Bounds checking, we need at least 2 elements on the vector. + // If it doesn't meet the requirements, return nullptr to keep it + // as-is. + if (vec.size() <= 1) return nullptr; + for (i = 0; i < vec.size() - 1; i++) { const int first = vec[i] - value; const int second = vec[i + 1] - value;