]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
MdePkg UefiDevicePathLib: Validate before touch input buffer.
[mirror_edk2.git] / MdePkg / Library / UefiDevicePathLib / DevicePathFromText.c
index b8966854b2f33110f4b2929e1edbc96b6d090a4a..c167b4ce031eb37ee34f53617b1851089544087c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   DevicePathFromText protocol as defined in the UEFI 2.0 specification.\r
 \r
-Copyright (c) 2013 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2013 - 2016, 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
@@ -1902,6 +1902,34 @@ DevPathFromTextSd (
   return (EFI_DEVICE_PATH_PROTOCOL *) Sd;\r
 }\r
 \r
+/**\r
+  Converts a text device path node to EMMC (Embedded MMC) device path structure.\r
+\r
+  @param TextDeviceNode  The input Text device path node.\r
+\r
+  @return A pointer to the newly-created EMMC device path structure.\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+DevPathFromTextEmmc (\r
+  IN CHAR16 *TextDeviceNode\r
+  )\r
+{\r
+  CHAR16            *SlotNumberStr;\r
+  EMMC_DEVICE_PATH  *Emmc;\r
+\r
+  SlotNumberStr = GetNextParamStr (&TextDeviceNode);\r
+  Emmc          = (EMMC_DEVICE_PATH *) CreateDeviceNode (\r
+                                       MESSAGING_DEVICE_PATH,\r
+                                       MSG_EMMC_DP,\r
+                                       (UINT16) sizeof (EMMC_DEVICE_PATH)\r
+                                       );\r
+\r
+  Emmc->SlotNumber = (UINT8) Strtoi (SlotNumberStr);\r
+\r
+  return (EFI_DEVICE_PATH_PROTOCOL *) Emmc;\r
+}\r
+\r
 /**\r
   Converts a text device path node to Debug Port device path structure.\r
 \r
@@ -2795,17 +2823,18 @@ DevPathFromTextBluetooth (
                                    );\r
 \r
   Index = sizeof (BLUETOOTH_ADDRESS) - 1;\r
-  while (!IS_NULL(BluetoothStr) && Index >= 0) {\r
-    Walker = SplitStr (&BluetoothStr, L':');\r
-    TempBufferSize = StrSize (Walker) + StrLen (L"0x") * sizeof (CHAR16);\r
+  Walker = BluetoothStr;\r
+  while (!IS_NULL(*Walker) && Index >= 0) {\r
+    TempBufferSize = 2 * sizeof(CHAR16) + StrSize(L"0x");\r
     TempNumBuffer = AllocateZeroPool (TempBufferSize);\r
     if (TempNumBuffer == NULL) {\r
       break;\r
     }\r
     StrCpyS (TempNumBuffer, TempBufferSize / sizeof (CHAR16), L"0x");\r
-    StrCatS (TempNumBuffer, TempBufferSize / sizeof (CHAR16), Walker);\r
+    StrnCatS (TempNumBuffer, TempBufferSize / sizeof (CHAR16), Walker, 2);\r
     BluetoothDp->BD_ADDR.Address[Index] = (UINT8)Strtoi (TempNumBuffer);\r
     FreePool (TempNumBuffer);\r
+    Walker += 2;\r
     Index--;\r
   }\r
   \r
@@ -2826,7 +2855,8 @@ DevPathFromTextWiFi (
   )\r
 {\r
   CHAR16                *SSIdStr;\r
-  CHAR8                 *AsciiStr;\r
+  CHAR8                 AsciiStr[33];\r
+  UINTN                 DataLen;\r
   WIFI_DEVICE_PATH      *WiFiDp;\r
 \r
   SSIdStr = GetNextParamStr (&TextDeviceNode);\r
@@ -2836,8 +2866,16 @@ DevPathFromTextWiFi (
                                    (UINT16) sizeof (WIFI_DEVICE_PATH)\r
                                    );\r
 \r
-  AsciiStr = (CHAR8 *) WiFiDp->SSId;\r
-  StrToAscii (SSIdStr, &AsciiStr);\r
+  if (NULL != SSIdStr) {\r
+    DataLen = StrLen (SSIdStr);\r
+    if (StrLen (SSIdStr) > 32) {\r
+      SSIdStr[32] = L'\0';\r
+      DataLen     = 32;\r
+    }\r
+\r
+    UnicodeStrToAsciiStrS (SSIdStr, AsciiStr, sizeof (AsciiStr));\r
+    CopyMem (WiFiDp->SSId, AsciiStr, DataLen);\r
+  }\r
 \r
   return (EFI_DEVICE_PATH_PROTOCOL *) WiFiDp;\r
 }\r
@@ -3457,7 +3495,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE mUefiDevicePathLibDevP
   {L"MemoryMapped",            DevPathFromTextMemoryMapped            },\r
   {L"VenHw",                   DevPathFromTextVenHw                   },\r
   {L"Ctrl",                    DevPathFromTextCtrl                    },\r
-  {L"Bmc",                     DevPathFromTextBmc                     },\r
+  {L"BMC",                     DevPathFromTextBmc                     },\r
 \r
   {L"AcpiPath",                DevPathFromTextAcpiPath                },\r
   {L"Acpi",                    DevPathFromTextAcpi                    },\r
@@ -3491,6 +3529,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE mUefiDevicePathLibDevP
   {L"NVMe",                    DevPathFromTextNVMe                    },\r
   {L"UFS",                     DevPathFromTextUfs                     },\r
   {L"SD",                      DevPathFromTextSd                      },\r
+  {L"Emmc",                    DevPathFromTextEmmc                    },\r
   {L"DebugPort",               DevPathFromTextDebugPort               },\r
   {L"MAC",                     DevPathFromTextMAC                     },\r
   {L"IPv4",                    DevPathFromTextIPv4                    },\r
@@ -3518,7 +3557,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE mUefiDevicePathLibDevP
   {L"Vlan",                    DevPathFromTextVlan                    },\r
   {L"Uri",                     DevPathFromTextUri                     },\r
   {L"Bluetooth",               DevPathFromTextBluetooth               },\r
-  {L"WiFi",                    DevPathFromTextWiFi                    },\r
+  {L"Wi-Fi",                   DevPathFromTextWiFi                    },\r
   {L"MediaPath",               DevPathFromTextMediaPath               },\r
   {L"HD",                      DevPathFromTextHD                      },\r
   {L"CDROM",                   DevPathFromTextCDROM                   },\r