1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-15 20:35:33 +03:00

Add fix for runtimeEntryFlags array overrun

This commit is contained in:
Pieter Kruger 2019-03-02 19:52:03 +10:00
parent 394807f558
commit d2e7abd5c6

View file

@ -231,6 +231,10 @@ static void cmsUpdateMaxRow(displayPort_t *instance)
pageMaxRow = maxMenuItems; pageMaxRow = maxMenuItems;
} }
if (pageMaxRow > CMS_MAX_ROWS) {
pageMaxRow = CMS_MAX_ROWS;
}
pageMaxRow--; pageMaxRow--;
} }
@ -249,7 +253,7 @@ static void cmsPageSelect(displayPort_t *instance, int8_t newpage)
const OSD_Entry *p; const OSD_Entry *p;
int i; int i;
for (p = pageTop, i = 0; p->type != OME_END; p++, i++) { for (p = pageTop, i = 0; (p <= pageTop + pageMaxRow); p++, i++) {
runtimeEntryFlags[i] = p->flags; runtimeEntryFlags[i] = p->flags;
} }
cmsUpdateMaxRow(instance); cmsUpdateMaxRow(instance);
@ -553,13 +557,13 @@ static void cmsDrawMenu(displayPort_t *pDisplay, uint32_t currentTimeUs)
uint32_t room = displayTxBytesFree(pDisplay); uint32_t room = displayTxBytesFree(pDisplay);
if (pDisplay->cleared) { if (pDisplay->cleared) {
for (p = pageTop, i= 0; p->type != OME_END; p++, i++) { for (p = pageTop, i= 0; (p <= pageTop + pageMaxRow); p++, i++) {
SET_PRINTLABEL(runtimeEntryFlags[i]); SET_PRINTLABEL(runtimeEntryFlags[i]);
SET_PRINTVALUE(runtimeEntryFlags[i]); SET_PRINTVALUE(runtimeEntryFlags[i]);
} }
pDisplay->cleared = false; pDisplay->cleared = false;
} else if (drawPolled) { } else if (drawPolled) {
for (p = pageTop, i = 0; p <= pageTop + pageMaxRow ; p++, i++) { for (p = pageTop, i = 0; (p <= pageTop + pageMaxRow); p++, i++) {
if (IS_DYNAMIC(p)) if (IS_DYNAMIC(p))
SET_PRINTVALUE(runtimeEntryFlags[i]); SET_PRINTVALUE(runtimeEntryFlags[i]);
} }
@ -588,7 +592,7 @@ static void cmsDrawMenu(displayPort_t *pDisplay, uint32_t currentTimeUs)
return; return;
// Print text labels // Print text labels
for (i = 0, p = pageTop; i < maxMenuItems && p->type != OME_END; i++, p++) { for (i = 0, p = pageTop; (p <= pageTop + pageMaxRow); i++, p++) {
if (IS_PRINTLABEL(runtimeEntryFlags[i])) { if (IS_PRINTLABEL(runtimeEntryFlags[i])) {
uint8_t coloff = leftMenuColumn; uint8_t coloff = leftMenuColumn;
coloff += (p->type == OME_Label) ? 0 : 1; coloff += (p->type == OME_Label) ? 0 : 1;
@ -774,7 +778,7 @@ long cmsMenuExit(displayPort_t *pDisplay, const void *ptr)
if (currentCtx.menu->onExit) if (currentCtx.menu->onExit)
currentCtx.menu->onExit((OSD_Entry *)NULL); // Forced exit currentCtx.menu->onExit((OSD_Entry *)NULL); // Forced exit
if ((exitType == CMS_POPUP_SAVE) || (exitType == CMS_POPUP_SAVEREBOOT)) { if ((exitType == CMS_POPUP_SAVE) || (exitType == CMS_POPUP_SAVEREBOOT)) {
// traverse through the menu stack and call their onExit functions // traverse through the menu stack and call their onExit functions
for (int i = menuStackIdx - 1; i >= 0; i--) { for (int i = menuStackIdx - 1; i >= 0; i--) {