From 6c8d08c0af4768c715b79c8ec25141d56e34f8b4 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Tue, 6 Mar 2018 15:16:51 -0500 Subject: shim: Ignore UEFI LoadOptions that are just NUL characters. I don't know when or why we ever see this, but it's easy enough to avoid. Resolves github issue #95 Signed-off-by: Peter Jones --- shim.c | 6 ++++++ ucs2.h | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/shim.c b/shim.c index 818eff39..34b819a9 100644 --- a/shim.c +++ b/shim.c @@ -2582,6 +2582,12 @@ EFI_STATUS set_second_stage (EFI_HANDLE image_handle) li->LoadOptionsSize -= 16; } + /* + * Apparently sometimes we get L"\0\0"? Which isn't useful at all. + */ + if (is_all_nuls(li->LoadOptions, li->LoadOptionsSize)) + return EFI_SUCCESS; + /* * Check and see if this is just a list of strings. If it's an * EFI_LOAD_OPTION, it'll be 0, since we know EndEntire device path diff --git a/ucs2.h b/ucs2.h index 010d0966..806774c7 100644 --- a/ucs2.h +++ b/ucs2.h @@ -36,6 +36,8 @@ #ifndef SHIM_UCS2_H #define SHIM_UCS2_H +#include + static inline INTN __attribute__((unused)) StrCaseCmp(CHAR16 *s0, CHAR16 *s1) @@ -89,6 +91,24 @@ StrCSpn(const CHAR16 *s, const CHAR16 *reject) return ret; } +/* + * Test if an entire buffer is nothing but NUL characters. This + * implementation "gracefully" ignores the difference between the + * UTF-8/ASCII 1-byte NUL and the UCS-2 2-byte NUL. + */ +static inline bool +__attribute__((__unused__)) +is_all_nuls(UINT8 *data, UINTN data_size) +{ + UINTN i; + + for (i = 0; i < data_size; i++) { + if (data[i] != 0) + return false; + } + return true; +} + static inline UINTN __attribute__((__unused__)) count_ucs2_strings(UINT8 *data, UINTN data_size) -- cgit v1.2.3