From ae3adc064579d9f41ea1c60583bed42f8518609a Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Thu, 31 Aug 2017 15:53:47 +0000 Subject: [PATCH] Fix parsing File() nodes in device paths. o Add File to the mUefiDevicePathLibDevPathFromTextTable table so we don't include 'File()' in the supposed path name. This happens because of a possible misfeature in the EDK2 code where any path that's not recognized is treated as a File() node. o Convert utf8 input into ucs2 output rather than just copying the utf8 and hoping for the best (no good comes from that). o Remove bogus comment about needing to add 1. The dummy array already is length 1, so that's included in sizeof the struct, so there's no need to add it. Sponsored by: Netflix --- lib/libefivar/efivar-dp-parse.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/libefivar/efivar-dp-parse.c b/lib/libefivar/efivar-dp-parse.c index c1ca9b72afca..1a280d70cfe3 100644 --- a/lib/libefivar/efivar-dp-parse.c +++ b/lib/libefivar/efivar-dp-parse.c @@ -38,6 +38,8 @@ __FBSDID("$FreeBSD$"); #include #include +#include "efichar.h" + #include "efi-osdep.h" #include "efivar-dp.h" @@ -3031,21 +3033,15 @@ DevPathFromTextFilePath ( StrCpyS (File->PathName, StrLen (TextDeviceNode) + 1, TextDeviceNode); #else + size_t len = (sizeof (FILEPATH_DEVICE_PATH) + StrLen (TextDeviceNode) * 2); + efi_char * v; File = (FILEPATH_DEVICE_PATH *) CreateDeviceNode ( MEDIA_DEVICE_PATH, MEDIA_FILEPATH_DP, - (UINT16) (sizeof (FILEPATH_DEVICE_PATH) + StrLen (TextDeviceNode) + 1) + (UINT16)len ); - - /* - * Note: We'd have to change the Tianocore header files to fix this - * to not need a cast. Instead we just cast it here. The Interface - * to the user may have issues since this won't be a UCS-2 - * string. Also note that in the original code, a NUL wasn't - * allocated for the end of the string, but we copy that below. This - * has been corrected. - */ - StrCpyS ((char *)File->PathName, StrLen (TextDeviceNode) + 1, TextDeviceNode); + v = File->PathName; + utf8_to_ucs2(TextDeviceNode, &v, &len); #endif return (EFI_DEVICE_PATH_PROTOCOL *) File; @@ -3560,6 +3556,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE mUefiDevicePathLibDevP {"Media", DevPathFromTextMedia }, {"Fv", DevPathFromTextFv }, {"FvFile", DevPathFromTextFvFile }, + {"File", DevPathFromTextFilePath }, {"Offset", DevPathFromTextRelativeOffsetRange }, {"RamDisk", DevPathFromTextRamDisk }, {"VirtualDisk", DevPathFromTextVirtualDisk },