Convert file name from wide char to narrow char

This commit is contained in:
jinlun 2023-07-13 19:49:41 +08:00
parent 5f3bbbc69e
commit 264a80036f
2 changed files with 67 additions and 1 deletions

View File

@ -0,0 +1,62 @@
From 5983ad49a335b8472c04a4cf1b8244df0ae77b6b Mon Sep 17 00:00:00 2001
From: jinlun <jinlun@huawei.com>
Date: Thu, 13 Jul 2023 19:43:22 +0800
Subject: [PATCH] Convert file name from wide char to narrow char
---
tpcm.c | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/tpcm.c b/tpcm.c
index fbd1da6..e98b3d7 100644
--- a/tpcm.c
+++ b/tpcm.c
@@ -98,17 +98,35 @@ static EFI_STATUS tpcm_get_response_blocked(void)
return efi_status;
}
+static void wide_char_to_multi_byte(CHAR16 *description, UINT8 *filename, UINT32 *filename_len)
+{
+ UINT8 *str = (UINT8 *)description;
+ UINT32 len = *filename_len;
+ UINT32 i;
+ *filename_len = 0;
+ for (i = 0; i < len; i++) {
+ if (str[i] == 0 || str[i] == '\\') {
+ continue;
+ }
+ filename[*filename_len] = str[i];
+ (*filename_len)++;
+ }
+ filename[*filename_len] = '\0';
+}
+
static EFI_STATUS tpcm_fillup_hash_content(OEM_BMC_MEASURE_REQUSET *request_data, unsigned char *content,
CHAR16 *description)
{
UINT32 filename_len = StrLen(description) * 2 + 1;
UINT32 stage_base = bm_stage_base++;
+ UINT8 filename[FIRMWARE_NAME_SIZE] = {0};
if (filename_len > FIRMWARE_NAME_SIZE) {
console_print(L"the path strings is pass the size of FirmwareHashContent.uaObj!\n");
return EFI_INVALID_PARAMETER;
}
+ wide_char_to_multi_byte(description, filename, &filename_len);
console_print(L"start filling the hash content.\n");
request_data->FirmwareHashContent.uiCmdTag = TRANS(TPCM_TAG_REQ_COMMAND);
request_data->FirmwareHashContent.uiCmdLength = TRANS(sizeof(extern_simple_bmeasure_req_st));
@@ -120,8 +138,7 @@ static EFI_STATUS tpcm_fillup_hash_content(OEM_BMC_MEASURE_REQUSET *request_data
memcpy((UINT8 *)(request_data->FirmwareHashContent.uaDigest), content, DEFAULT_HASH_SIZE);
request_data->FirmwareHashContent.uiObjLen = TRANS(filename_len);
- memcpy((UINT8 *)(request_data->FirmwareHashContent.uaObj), description, filename_len);
- request_data->FirmwareHashContent.uaObj[filename_len - 1] = '\0';
+ memcpy((UINT8 *)(request_data->FirmwareHashContent.uaObj), filename, filename_len);
return EFI_SUCCESS;
}
--
2.27.0

View File

@ -22,7 +22,7 @@
Name: shim
Version: 15
Release: 31
Release: 32
Summary: First-stage UEFI bootloader
ExclusiveArch: x86_64 aarch64
License: BSD
@ -59,6 +59,7 @@ Patch22: backport-CVE-2023-0286.patch
Patch9000: Feature-add-tpcm-support-with-ipmi-channel.patch
Patch9001: fix-the-bug-for-fb-and-mok-do-some-clean-code.patch
Patch9002: Feature-add-control-switch-to-optimized-exception-handling.patch
Patch9003: Feature-Convert-file-name-from-wide-char-to-narrow-char.patch
BuildRequires: elfutils-libelf-devel openssl-devel openssl git pesign gnu-efi gnu-efi-devel gcc
Requires: dbxtool efi-filesystem mokutil
@ -157,6 +158,9 @@ cd ..
/usr/src/debug/%{name}-%{version}-%{release}/*
%changelog
* Thu Jul 13 2023 jinlun <jinlun@huawei.com> - 15-32
- Convert file name from wide char to narrow char
* Wed Jun 14 2023 jinlun <jinlun@huawei.com> - 15-31
- add control switch to optimized exception handling.