diff options
| author | Peter Jones <pjones@redhat.com> | 2021-09-16 16:43:24 -0400 |
|---|---|---|
| committer | Peter Jones <pjones@redhat.com> | 2021-10-12 10:40:13 -0400 |
| commit | 1872c929cc3a466c75336307901e67917bcc46bc (patch) | |
| tree | 0b229857c707d70b15083ab54716d4d899722445 /lib/console.c | |
| parent | 41319e14c9144063605750baccd5bb332a3cf4fc (diff) | |
| download | efi-boot-shim-1872c929cc3a466c75336307901e67917bcc46bc.tar.gz efi-boot-shim-1872c929cc3a466c75336307901e67917bcc46bc.zip | |
console: check that ST->ConIn and ST->ConOut are non-NULL
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>
Diffstat (limited to 'lib/console.c')
| -rw-r--r-- | lib/console.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/lib/console.c b/lib/console.c index 2a669228..6b1e4c2f 100644 --- a/lib/console.c +++ b/lib/console.c @@ -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); @@ -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); @@ -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 */ @@ -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); @@ -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++) { @@ -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); @@ -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); @@ -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; @@ -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); @@ -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); |
