From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.115; helo=mga14.intel.com; envelope-from=hao.a.wu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 1E4C321173C6E for ; Thu, 18 Oct 2018 20:06:20 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Oct 2018 20:06:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,398,1534834800"; d="scan'208";a="93233953" Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.9]) by orsmga003.jf.intel.com with ESMTP; 18 Oct 2018 20:06:18 -0700 From: Hao Wu To: edk2-devel@lists.01.org Cc: Hao Wu , "Bin . Lain" , Jiewen Yao , Michael D Kinney , Liming Gao Date: Fri, 19 Oct 2018 11:06:15 +0800 Message-Id: <20181019030615.9716-1-hao.a.wu@intel.com> X-Mailer: git-send-email 2.12.0.windows.1 Subject: [PATCH] MdePkg/BaseLib: AsciiStrToUnicodeStr(S) not handle EASCII properly X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Oct 2018 03:06:21 -0000 REF:https://bugzilla.tianocore.org/show_bug.cgi?id=1262 Current implementation of BaseLib APIs: AsciiStrToUnicodeStr() AsciiStrToUnicodeStrS() AsciiStrnToUnicodeStrS() do not handle EASCII properly. More specifically, if the value of ASCII character is larger than 0x7F, then the converted Unicode character will have all '1's in the higher 8 bits. An example: 0xC9 => 0xFFC9 (current implementations) and it should be: 0xC9 => 0x00C9 This commit will address this issue. Cc: Bin.Lain Cc: Jiewen Yao Cc: Michael D Kinney Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu --- MdePkg/Library/BaseLib/SafeString.c | 4 ++-- MdePkg/Library/BaseLib/String.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/MdePkg/Library/BaseLib/SafeString.c b/MdePkg/Library/BaseLib/SafeString.c index 29310889ca..417497cbc9 100644 --- a/MdePkg/Library/BaseLib/SafeString.c +++ b/MdePkg/Library/BaseLib/SafeString.c @@ -2932,7 +2932,7 @@ AsciiStrToUnicodeStrS ( // Convert string // while (*Source != '\0') { - *(Destination++) = (CHAR16)*(Source++); + *(Destination++) = (CHAR16)(UINT8)*(Source++); } *Destination = '\0'; @@ -3045,7 +3045,7 @@ AsciiStrnToUnicodeStrS ( // Convert string // while ((*Source != 0) && (SourceLen > 0)) { - *(Destination++) = (CHAR16)*(Source++); + *(Destination++) = (CHAR16)(UINT8)*(Source++); SourceLen--; (*DestinationLength)++; } diff --git a/MdePkg/Library/BaseLib/String.c b/MdePkg/Library/BaseLib/String.c index cb90774c86..e6df12797d 100644 --- a/MdePkg/Library/BaseLib/String.c +++ b/MdePkg/Library/BaseLib/String.c @@ -1746,7 +1746,7 @@ AsciiStrToUnicodeStr ( ReturnValue = Destination; while (*Source != '\0') { - *(Destination++) = (CHAR16) *(Source++); + *(Destination++) = (CHAR16)(UINT8) *(Source++); } // // End the Destination with a NULL. -- 2.12.0.windows.1