Skip to content

Commit

Permalink
console: check that ST->ConIn and ST->ConOut are non-NULL
Browse files Browse the repository at this point in the history
There's been some discussion on how to handle machines without console
devices.  The consensus so far has been that they should have dummy
ConOut implementations, but that means the first vendor to build a
machine without asking around is in for some surprises.

This patch makes the places where our console library uses ST->ConIn or
ST->ConOut check that they're present before doing so.

Signed-off-by: Peter Jones <pjones@redhat.com>
  • Loading branch information
vathpela committed Oct 12, 2021
1 parent 41319e1 commit 1872c92
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion lib/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ console_get_keystroke(EFI_INPUT_KEY *key)
UINTN EventIndex;
EFI_STATUS efi_status;

if (!ci)
return EFI_UNSUPPORTED;

do {
BS->WaitForEvent(1, &ci->WaitForKey, &EventIndex);
efi_status = ci->ReadKeyStroke(ci, key);
Expand Down Expand Up @@ -109,7 +112,8 @@ console_print_at(UINTN col, UINTN row, const CHAR16 *fmt, ...)
if (!console_text_mode)
setup_console(1);

co->SetCursorPosition(co, col, row);
if (co)
co->SetCursorPosition(co, col, row);

ms_va_start(args, fmt);
ret = VPrint(fmt, args);
Expand All @@ -136,6 +140,9 @@ console_print_box_at(CHAR16 *str_arr[], int highlight,
if (!console_text_mode)
setup_console(1);

if (!co)
return;

co->QueryMode(co, co->Mode->Mode, &cols, &rows);

/* last row on screen is unusable without scrolling, so ignore it */
Expand Down Expand Up @@ -241,6 +248,9 @@ console_print_box(CHAR16 *str_arr[], int highlight)
if (!console_text_mode)
setup_console(1);

if (!co)
return;

CopyMem(&SavedConsoleMode, co->Mode, sizeof(SavedConsoleMode));
co->EnableCursor(co, FALSE);
co->SetAttribute(co, EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE);
Expand Down Expand Up @@ -274,6 +284,9 @@ console_select(CHAR16 *title[], CHAR16* selectors[], unsigned int start)
if (!console_text_mode)
setup_console(1);

if (!co)
return -1;

co->QueryMode(co, co->Mode->Mode, &cols, &rows);

for (i = 0; i < selector_lines; i++) {
Expand Down Expand Up @@ -413,6 +426,9 @@ console_save_and_set_mode(SIMPLE_TEXT_OUTPUT_MODE * SavedMode)
return;
}

if (!co)
return;

CopyMem(SavedMode, co->Mode, sizeof(SIMPLE_TEXT_OUTPUT_MODE));
co->EnableCursor(co, FALSE);
co->SetAttribute(co, EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE);
Expand All @@ -423,6 +439,9 @@ console_restore_mode(SIMPLE_TEXT_OUTPUT_MODE * SavedMode)
{
SIMPLE_TEXT_OUTPUT_INTERFACE *co = ST->ConOut;

if (!co)
return;

co->EnableCursor(co, SavedMode->CursorVisible);
co->SetCursorPosition(co, SavedMode->CursorColumn,
SavedMode->CursorRow);
Expand All @@ -441,6 +460,9 @@ console_countdown(CHAR16* title, const CHAR16* message, int timeout)
CHAR16 *titles[2];
int wait = 10000000;

if (!co || !ci)
return -1;

console_save_and_set_mode(&SavedMode);

titles[0] = title;
Expand Down Expand Up @@ -495,6 +517,9 @@ console_mode_handle(VOID)
UINTN rows = 0, columns = 0;
EFI_STATUS efi_status = EFI_SUCCESS;

if (!co)
return;

efi_status = BS->LocateProtocol(&gop_guid, NULL, (void **)&gop);
if (EFI_ERROR(efi_status)) {
console_error(L"Locate graphic output protocol fail", efi_status);
Expand Down Expand Up @@ -649,6 +674,9 @@ console_reset(void)
if (!console_text_mode)
setup_console(1);

if (!co)
return;

co->Reset(co, TRUE);
/* set mode 0 - required to be 80x25 */
co->SetMode(co, 0);
Expand Down

0 comments on commit 1872c92

Please sign in to comment.