Revision: 18358
          http://sourceforge.net/p/edk2/code/18358
Author:   hwu1225
Date:     2015-08-28 07:51:45 +0000 (Fri, 28 Aug 2015)
Log Message:
-----------
MdePkg UefiDevicePathLib: Fix possible memory read/write cross boundary

The SSID field of a Wi-Fi device path node may not contain a NULL
termination.

Additonal handle is added to make sure no cross-boundary memory read/write
will occur.

(Sync patch r18355 from main trunk.)

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <[email protected]>
Reviewed-by: Feng Tian <[email protected]>

Revision Links:
--------------
    http://sourceforge.net/p/edk2/code/18355

Modified Paths:
--------------
    branches/UDK2015/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
    branches/UDK2015/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c

Modified: branches/UDK2015/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
===================================================================
--- branches/UDK2015/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c      
2015-08-28 07:51:16 UTC (rev 18357)
+++ branches/UDK2015/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c      
2015-08-28 07:51:45 UTC (rev 18358)
@@ -2827,7 +2827,8 @@
   )
 {
   CHAR16                *SSIdStr;
-  CHAR8                 *AsciiStr;
+  CHAR8                 AsciiStr[33];
+  UINTN                 DataLen;
   WIFI_DEVICE_PATH      *WiFiDp;
 
   SSIdStr = GetNextParamStr (&TextDeviceNode);
@@ -2837,9 +2838,17 @@
                                    (UINT16) sizeof (WIFI_DEVICE_PATH)
                                    );
 
-  AsciiStr = (CHAR8 *) WiFiDp->SSId;
-  StrToAscii (SSIdStr, &AsciiStr);
+  if (NULL != SSIdStr) {
+    DataLen = StrLen (SSIdStr);
+    if (StrLen (SSIdStr) > 32) {
+      SSIdStr[32] = L'\0';
+      DataLen     = 32;
+    }
 
+    UnicodeStrToAsciiStr (SSIdStr, AsciiStr);
+    CopyMem (WiFiDp->SSId, AsciiStr, DataLen);
+  }
+
   return (EFI_DEVICE_PATH_PROTOCOL *) WiFiDp;
 }
 

Modified: branches/UDK2015/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c
===================================================================
--- branches/UDK2015/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c        
2015-08-28 07:51:16 UTC (rev 18357)
+++ branches/UDK2015/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c        
2015-08-28 07:51:45 UTC (rev 18358)
@@ -1616,9 +1616,14 @@
   )
 {
   WIFI_DEVICE_PATH      *WiFi;
+  UINT8                 SSId[33];
 
   WiFi = DevPath;
-  UefiDevicePathLibCatPrint (Str, L"Wi-Fi(%a)", WiFi->SSId);
+
+  SSId[32] = '\0';
+  CopyMem (SSId, WiFi->SSId, 32);
+
+  UefiDevicePathLibCatPrint (Str, L"Wi-Fi(%a)", SSId);
 }
 
 /**


------------------------------------------------------------------------------
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to