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

