From 1138c4dd6ae04e5821676ae196a25cbb1ad314c3 Mon Sep 17 00:00:00 2001 From: Bruce Luckcuck Date: Tue, 10 Sep 2019 15:40:11 -0400 Subject: [PATCH] Add missing boundary checks in vtx_common for band, channel and powerlevel index Previously there were cases where the input was not compared to the currently defined vtxtable limits and this could lead to a wedge as code referenced the uninitialize string arrays. --- src/main/drivers/vtx_common.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/drivers/vtx_common.c b/src/main/drivers/vtx_common.c index 49ed89adf2..0372518fc0 100644 --- a/src/main/drivers/vtx_common.c +++ b/src/main/drivers/vtx_common.c @@ -148,7 +148,7 @@ bool vtxCommonGetStatus(const vtxDevice_t *vtxDevice, unsigned *status) const char *vtxCommonLookupBandName(const vtxDevice_t *vtxDevice, int band) { - if (vtxDevice) { + if (vtxDevice && band > 0 && band <= vtxTableBandCount) { return vtxTableBandNames[band]; } else { return "?"; @@ -157,7 +157,7 @@ const char *vtxCommonLookupBandName(const vtxDevice_t *vtxDevice, int band) char vtxCommonLookupBandLetter(const vtxDevice_t *vtxDevice, int band) { - if (vtxDevice) { + if (vtxDevice && band > 0 && band <= vtxTableBandCount) { return vtxTableBandLetters[band]; } else { return '?'; @@ -166,7 +166,7 @@ char vtxCommonLookupBandLetter(const vtxDevice_t *vtxDevice, int band) const char *vtxCommonLookupChannelName(const vtxDevice_t *vtxDevice, int channel) { - if (vtxDevice) { + if (vtxDevice && channel > 0 && channel <= vtxTableChannelCount) { return vtxTableChannelNames[channel]; } else { return "?"; @@ -214,7 +214,7 @@ uint16_t vtxCommonLookupFrequency(const vtxDevice_t *vtxDevice, int band, int ch const char *vtxCommonLookupPowerName(const vtxDevice_t *vtxDevice, int index) { - if (vtxDevice) { + if (vtxDevice && index > 0 && index <= vtxTablePowerLevels) { return vtxTablePowerLabels[index]; } else { return "?";