From 6e1bd3dcb70985e81f1f9d133219b708eb9beddd Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Fri, 26 Apr 2013 11:44:15 -0400 Subject: UEFI Shell sticks the UCS2 of li->FilePath in li->LoadOptions. Ignore it. If li->LoadOptions tells us to execute our own binary, it's clearly not what we want to do for the second stage. So simply ignore that case. Signed-off-by: Peter Jones --- ucs2.h | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 ucs2.h (limited to 'ucs2.h') diff --git a/ucs2.h b/ucs2.h new file mode 100644 index 00000000..7c49b09b --- /dev/null +++ b/ucs2.h @@ -0,0 +1,57 @@ +/* + * shim - trivial UEFI first-stage bootloader + * + * Copyright 2013 Red Hat, Inc + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Significant portions of this code are derived from Tianocore + * (http://tianocore.sf.net) and are Copyright 2009-2012 Intel + * Corporation. + */ + +#ifndef SHIM_UCS2_H +#define SHIM_UCS2_H + +static inline INTN +__attribute__((unused)) +StrCaseCmp(CHAR16 *s0, CHAR16 *s1) +{ + CHAR16 c0, c1; + while (1) { + if (*s0 == L'\0' || *s1 == L'\0') + return *s1 - *s0; + c0 = (*s0 >= L'a' && *s0 <= L'z') ? *s0 - 32 : *s0; + c1 = (*s1 >= L'a' && *s1 <= L'z') ? *s1 - 32 : *s1; + if (c0 != c1) + return c1 - c0; + s0++; + s1++; + } + return 0; +} + +#endif /* SHIM_UCS2_H */ -- cgit v1.2.3 From 155a76bb8657c6521be71ab3da609ae181376150 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Fri, 26 Apr 2013 11:44:28 -0400 Subject: Don't put the directory in the file path twice. Sometimes when we're creating paths, the ImagePath can contain the directory name already. If that happens, don't add it in again. Signed-off-by: Peter Jones --- shim.c | 3 ++- ucs2.h | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'ucs2.h') diff --git a/shim.c b/shim.c index 32b3ae95..7abbe8b4 100644 --- a/shim.c +++ b/shim.c @@ -939,7 +939,8 @@ static EFI_STATUS generate_path(EFI_LOADED_IMAGE *li, CHAR16 *ImagePath, } *PathName[0] = '\0'; - StrCat(*PathName, bootpath); + if (StrnCaseCmp(bootpath, ImagePath, StrLen(bootpath))) + StrCat(*PathName, bootpath); StrCat(*PathName, ImagePath); *grubpath = FileDevicePath(device, *PathName); diff --git a/ucs2.h b/ucs2.h index 7c49b09b..03742847 100644 --- a/ucs2.h +++ b/ucs2.h @@ -54,4 +54,23 @@ StrCaseCmp(CHAR16 *s0, CHAR16 *s1) return 0; } +static inline INTN +__attribute__((unused)) +StrnCaseCmp(CHAR16 *s0, CHAR16 *s1, int n) +{ + CHAR16 c0, c1; + int x = 0; + while (n > x++) { + if (*s0 == L'\0' || *s1 == L'\0') + return *s1 - *s0; + c0 = (*s0 >= L'a' && *s0 <= L'z') ? *s0 - 32 : *s0; + c1 = (*s1 >= L'a' && *s1 <= L'z') ? *s1 - 32 : *s1; + if (c0 != c1) + return c1 - c0; + s0++; + s1++; + } + return 0; +} + #endif /* SHIM_UCS2_H */ -- cgit v1.2.3 From 8f6eace1897d210ec98fdc358f51345021b5a892 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Tue, 30 Apr 2013 09:46:22 -0400 Subject: Add StrCSpn() Signed-off-by: Peter Jones --- ucs2.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'ucs2.h') diff --git a/ucs2.h b/ucs2.h index 03742847..d2ad6490 100644 --- a/ucs2.h +++ b/ucs2.h @@ -73,4 +73,20 @@ StrnCaseCmp(CHAR16 *s0, CHAR16 *s1, int n) return 0; } +static inline UINTN +__attribute__((unused)) +StrCSpn(const CHAR16 *s, const CHAR16 *reject) +{ + UINTN ret; + + for (ret = 0; s[ret] != L'\0'; ret++) { + int i; + for (i = 0; reject[i] != L'\0'; i++) { + if (reject[i] == s[ret]) + return ret; + } + } + return ret; +} + #endif /* SHIM_UCS2_H */ -- cgit v1.2.3