]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/Bds/BootMenu.c
ArmPkg/ArmDisassemblerLib: ARMThumb and AArch64 fixes
[mirror_edk2.git] / ArmPlatformPkg / Bds / BootMenu.c
index 42212385a860fcd13e6714a8b613fe705aa230e9..91e00b759ee48bb2073c34907f5f4d3f4b215d46 100644 (file)
@@ -555,7 +555,8 @@ BootMenuUpdateBootOption (
 \r
     Print(L"Arguments to pass to the binary: ");\r
     if (CmdLineSize > 0) {\r
-      AsciiStrnCpy(CmdLine, (CONST CHAR8*)(LinuxArguments + 1), CmdLineSize);\r
+      AsciiStrnCpy (CmdLine, (CONST CHAR8*)(LinuxArguments + 1), sizeof (CmdLine));\r
+      CmdLine[sizeof (CmdLine) - 1] = '\0';\r
     } else {\r
       CmdLine[0] = '\0';\r
     }\r
@@ -581,10 +582,29 @@ BootMenuUpdateBootOption (
     if (BootOption->OptionalDataSize > 0) {\r
       IsPrintable = IsPrintableString (BootOption->OptionalData, &IsUnicode);\r
       if (IsPrintable) {\r
+          //\r
+          // The size in bytes of the string, final zero included, should\r
+          // be equal to or at least lower than "BootOption->OptionalDataSize"\r
+          // and the "IsPrintableString()" has already tested that the length\r
+          // in number of characters is smaller than BOOT_DEVICE_OPTION_MAX,\r
+          // final '\0' included. We can thus copy the string for editing\r
+          // using "CopyMem()". Furthermore, note that in the case of an Unicode\r
+          // string "StrnCpy()" and "StrCpy()" can not be used to copy the\r
+          // string because the data pointed to by "BootOption->OptionalData"\r
+          // is not necessarily 2-byte aligned.\r
+          //\r
         if (IsUnicode) {\r
-          StrnCpy (UnicodeCmdLine, BootOption->OptionalData, BootOption->OptionalDataSize / 2);\r
+          CopyMem (\r
+            UnicodeCmdLine, BootOption->OptionalData,\r
+            MIN (sizeof (UnicodeCmdLine),\r
+                 BootOption->OptionalDataSize)\r
+            );\r
         } else {\r
-          AsciiStrnCpy (CmdLine, BootOption->OptionalData, BootOption->OptionalDataSize);\r
+          CopyMem (\r
+            CmdLine, BootOption->OptionalData,\r
+            MIN (sizeof (CmdLine),\r
+                 BootOption->OptionalDataSize)\r
+            );\r
         }\r
       }\r
     } else {\r
@@ -691,6 +711,7 @@ BootMenuReorderBootOptions (
     }\r
 \r
     SelectedEntry = &BootOptionEntry->Link;\r
+    SecondEntry = NULL;\r
     // Note down the previous entry in the list to be able to cancel changes\r
     PrevEntry = GetPreviousNode (BootOptionsList, SelectedEntry);\r
 \r
@@ -739,7 +760,9 @@ BootMenuReorderBootOptions (
       } while ((!Move) && (!Save) && (!Cancel));\r
 \r
       if (Move) {\r
-        SwapListEntries (SelectedEntry, SecondEntry);\r
+        if ((SelectedEntry != NULL) && (SecondEntry != NULL)) {\r
+          SwapListEntries (SelectedEntry, SecondEntry);\r
+        }\r
       } else {\r
         if (Save) {\r
           Status = GetGlobalEnvironmentVariable (\r