From b9e32d7a34d80776f2f8dfd8f6feae10f47fe12b Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Sat, 14 Jan 2017 14:12:18 +0100 Subject: [PATCH] mixer test: Fix string handling Some strings were not enforcing NUL termination. --- src/systemcmds/tests/test_mixer.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/systemcmds/tests/test_mixer.cpp b/src/systemcmds/tests/test_mixer.cpp index ea76808300..2ce8e3cd4a 100644 --- a/src/systemcmds/tests/test_mixer.cpp +++ b/src/systemcmds/tests/test_mixer.cpp @@ -216,7 +216,9 @@ bool MixerTest::loadAllTest() if (strncmp(result->d_name, ".", 1) != 0) { char buf[PATH_MAX]; - (void)strncpy(&buf[0], MIXER_ONBOARD_PATH, sizeof(buf)); + (void)strncpy(&buf[0], MIXER_ONBOARD_PATH, sizeof(buf) - 1); + /* enforce null termination */ + buf[sizeof(buf) - 1] = '\0'; (void)strncpy(&buf[strlen(MIXER_ONBOARD_PATH)], "/", 1); (void)strncpy(&buf[strlen(MIXER_ONBOARD_PATH) + 1], result->d_name, sizeof(buf) - strlen(MIXER_ONBOARD_PATH) - 1); @@ -597,7 +599,7 @@ mixer_callback(uintptr_t handle, uint8_t control_group, uint8_t control_index, f return -1; } - if (control_index > (sizeof(actuator_controls) / sizeof(actuator_controls[0]))) { + if (control_index >= (sizeof(actuator_controls) / sizeof(actuator_controls[0]))) { return -1; }