]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/DevicePath/DevicePathFromText.c
BaseTools: Fix bug when converting iSCSI node
[mirror_edk2.git] / BaseTools / Source / C / DevicePath / DevicePathFromText.c
index 3d2f5a811c4f7407a1f03688a534311e98d8df1b..fd310c7d0f75065ed910f143c0a7683f3f42962e 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   DevicePathFromText protocol as defined in the UEFI 2.0 specification.\r
 \r
-Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -2426,7 +2426,7 @@ DevPathFromTextiSCSI (
 \r
   ISCSIDevPath->LoginOption      = (UINT16) Options;\r
 \r
-  if (StrCmp (ProtocolStr, L"TCP") == 0) {\r
+  if (IS_NULL (*ProtocolStr) || (StrCmp (ProtocolStr, L"TCP") == 0)) {\r
     ISCSIDevPath->NetworkProtocol = 0;\r
   } else {\r
     //\r
@@ -3277,6 +3277,17 @@ UefiDevicePathLibConvertTextToDeviceNode (
     //\r
     FromText = DevPathFromTextFilePath;\r
     DeviceNode = FromText (DeviceNodeStr);\r
+    //\r
+    // According to above logic, if 'FromText' is NULL in the 'if' statement,\r
+    // then 'ParamStr' must be NULL as well. No memory allocation has been made\r
+    // in this case.\r
+    //\r
+    // The below check is for addressing a false positive potential memory leak\r
+    // issue raised from static analysis.\r
+    //\r
+    if (ParamStr != NULL) {\r
+      free (ParamStr);\r
+    }\r
   } else {\r
     DeviceNode = FromText (ParamStr);\r
     free (ParamStr);\r