libpayload: Fix payload .bss corruption

Third call to newwin() corrupted payload context.
Fix array indexing and check for boundary.

Sample payload coreinfo was affected, loader_eax
variable got corrupted on my particular build.

Change-Id: Iee98901cf57f0689f65ac43aa7e60e8aea092500
Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Reviewed-on: https://review.coreboot.org/26394
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
This commit is contained in:
Kyösti Mälkki 2018-05-19 08:58:01 +03:00
parent 0b71cf164b
commit 185202c469
1 changed files with 8 additions and 3 deletions

View File

@ -65,7 +65,7 @@
/* Statically allocate all structures (no malloc())! */
static WINDOW window_list[MAX_WINDOWS];
static int window_count = 1;
static int window_count = 0;
// struct ldat foo;
static struct ldat ldat_list[MAX_WINDOWS][SCREEN_Y];
@ -386,12 +386,17 @@ int mvwprintw(WINDOW *win, int y, int x, const char *fmt, ...)
// SCREEN *newterm (NCURSES_CONST char *,FILE *,FILE *) {}
WINDOW *newwin(int num_lines, int num_columns, int begy, int begx)
{
WINDOW *win;
int i;
/* Use next statically allocated window. */
// TODO: Error handling.
// TODO: Error handling. Yes. Please.
// TODO: WINDOWLIST?
WINDOW *win = &window_list[window_count++];
if (window_count >= MAX_WINDOWS)
return NULL;
win = &window_list[window_count++];
// bool is_pad = (flags & _ISPAD);