[edk2] [Patch] MdePkg/UefiDevicePathLib: Refine the DevPathFromTextiSCSI protocol parsing

Jiaxin Wu posted 1 patch 7 years, 7 months ago
Failed in applying to current master (apply log)
MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
[edk2] [Patch] MdePkg/UefiDevicePathLib: Refine the DevPathFromTextiSCSI protocol parsing
Posted by Jiaxin Wu 7 years, 7 months ago
For current iSCSI protocol parsing, UINT16 truncation may be happened. Since
the Spec already have declaimed that 0 is TCP Protocol and 1+ is reserved, the
parsing can be refined as below:

  if (StrCmp (ProtocolStr, L"TCP") == 0) {
    ISCSIDevPath->NetworkProtocol = 0;
  } else {
    //
    // Undefined and reserved.
    //
    ISCSIDevPath->NetworkProtocol = 1;
  }

Cc: Warner Losh <imp@bsdimp.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com>
---
 MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c b/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
index 3c9df28..4322b6c 100644
--- a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
+++ b/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
@@ -2579,11 +2579,18 @@ DevPathFromTextiSCSI (
     Options |= 0x1000;
   }
 
   ISCSIDevPath->LoginOption      = (UINT16) Options;
 
-  ISCSIDevPath->NetworkProtocol  = (UINT16) StrCmp (ProtocolStr, L"TCP");
+  if (StrCmp (ProtocolStr, L"TCP") == 0) {
+    ISCSIDevPath->NetworkProtocol = 0;
+  } else {
+    //
+    // Undefined and reserved.
+    //
+    ISCSIDevPath->NetworkProtocol = 1;
+  }
 
   return (EFI_DEVICE_PATH_PROTOCOL *) ISCSIDevPath;
 }
 
 /**
-- 
1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel