public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Ruiyu Ni <ruiyu.ni@intel.com>
To: edk2-devel@lists.01.org
Cc: Jie Lin <jie.lin@intel.com>, Liming Gao <liming.gao@intel.com>,
	Yonghong Zhu <yonghong.zhu@intel.com>
Subject: [PATCH 2/2] MdePkg/DevicePathFromText: Fix byte orders when handling 8-byte array
Date: Fri,  2 Mar 2018 19:52:06 +0800	[thread overview]
Message-ID: <20180302115206.143528-3-ruiyu.ni@intel.com> (raw)
In-Reply-To: <20180302115206.143528-1-ruiyu.ni@intel.com>

Per UEFI spec, FibreEx.WWN, FibreEx.Lun, SasEx.Address, SasEx.Lun
and iSCSI.Lun are all 8-byte array with byte #0 in the left.
It means "0102030405060708" should be converted to:
    UINT8[8] = {01, 02, 03, 04, 05, 06, 07, 08}
or  UINT64 = {0807060504030201}

Today's implementation wrongly uses the reversed order.
The patch fixes this issue by using StrHexToBytes().

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Jie Lin <jie.lin@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
---
 .../Library/UefiDevicePathLib/DevicePathFromText.c | 32 ++++++++++++++--------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c b/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
index c66b77ba6c..63cbc9449b 100644
--- a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
+++ b/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
@@ -1140,11 +1140,14 @@ DevPathFromTextFibreEx (
                                              );
 
   FibreEx->Reserved = 0;
-  Strtoi64 (WWNStr, (UINT64 *) (&FibreEx->WWN));
-  Strtoi64 (LunStr, (UINT64 *) (&FibreEx->Lun));
-
-  *(UINT64 *) (&FibreEx->WWN) = SwapBytes64 (*(UINT64 *) (&FibreEx->WWN));
-  *(UINT64 *) (&FibreEx->Lun) = SwapBytes64 (*(UINT64 *) (&FibreEx->Lun));
+  StrHexToBytes (
+    WWNStr, sizeof (FibreEx->WWN) * 2,
+    FibreEx->WWN, sizeof (FibreEx->WWN)
+    );
+  StrHexToBytes (
+    LunStr, sizeof (FibreEx->Lun) * 2,
+    FibreEx->Lun, sizeof (FibreEx->Lun)
+    );
 
   return (EFI_DEVICE_PATH_PROTOCOL *) FibreEx;
 }
@@ -1546,8 +1549,6 @@ DevPathFromTextSasEx (
   CHAR16            *DriveBayStr;
   UINT16            Info;
   UINT16            Uint16;
-  UINT64            SasAddress;
-  UINT64            Lun;
   SASEX_DEVICE_PATH *SasEx;
 
   AddressStr  = GetNextParamStr (&TextDeviceNode);
@@ -1563,10 +1564,14 @@ DevPathFromTextSasEx (
                                         (UINT16) sizeof (SASEX_DEVICE_PATH)
                                         );
 
-  Strtoi64 (AddressStr, &SasAddress);
-  Strtoi64 (LunStr,     &Lun);
-  WriteUnaligned64 ((UINT64 *) &SasEx->SasAddress, SwapBytes64 (SasAddress));
-  WriteUnaligned64 ((UINT64 *) &SasEx->Lun,        SwapBytes64 (Lun));
+  StrHexToBytes (
+    AddressStr, sizeof (SasEx->SasAddress) * 2,
+    SasEx->SasAddress, sizeof (SasEx->SasAddress)
+    );
+  StrHexToBytes (
+    LunStr, sizeof (SasEx->Lun) * 2,
+    SasEx->Lun, sizeof (SasEx->Lun)
+    );
   SasEx->RelativeTargetPort      = (UINT16) Strtoi (RTPStr);
 
   if (StrCmp (SASSATAStr, L"NoTopology") == 0) {
@@ -2560,7 +2565,10 @@ DevPathFromTextiSCSI (
   StrToAscii (NameStr, &AsciiStr);
 
   ISCSIDevPath->TargetPortalGroupTag = (UINT16) Strtoi (PortalGroupStr);
-  Strtoi64 (LunStr, &ISCSIDevPath->Lun);
+  StrHexToBytes (
+    LunStr, sizeof (ISCSIDevPath->Lun) * 2,
+    (UINT8 *)&ISCSIDevPath->Lun, sizeof (ISCSIDevPath->Lun)
+    );
 
   Options = 0x0000;
   if (StrCmp (HeaderDigestStr, L"CRC32C") == 0) {
-- 
2.16.1.windows.1



  parent reply	other threads:[~2018-03-02 11:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-02 11:52 [PATCH 0/2] Bug fix in DevicePathLib regarding converting from text Ruiyu Ni
2018-03-02 11:52 ` [PATCH 1/2] MdePkg/DevicePathFromText: Fix bug when converting iSCSI node Ruiyu Ni
2018-03-02 13:53   ` Gao, Liming
2018-03-02 11:52 ` Ruiyu Ni [this message]
2018-03-02 13:53   ` [PATCH 2/2] MdePkg/DevicePathFromText: Fix byte orders when handling 8-byte array Gao, Liming

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180302115206.143528-3-ruiyu.ni@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox