Revision: 16009
          http://sourceforge.net/p/edk2/code/16009
Author:   oliviermartin
Date:     2014-09-01 13:17:23 +0000 (Mon, 01 Sep 2014)
Log Message:
-----------
ArmPlatformPkg/Bds: Corrected a bug in IsPrintableString()

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ronald Cron <[email protected]>
Reviewed-by: Olivier Martin <[email protected]>

Modified Paths:
--------------
    trunk/edk2/ArmPlatformPkg/Bds/BootMenu.c

Modified: trunk/edk2/ArmPlatformPkg/Bds/BootMenu.c
===================================================================
--- trunk/edk2/ArmPlatformPkg/Bds/BootMenu.c    2014-09-01 08:48:01 UTC (rev 
16008)
+++ trunk/edk2/ArmPlatformPkg/Bds/BootMenu.c    2014-09-01 13:17:23 UTC (rev 
16009)
@@ -555,7 +555,8 @@
 
     Print(L"Arguments to pass to the binary: ");
     if (CmdLineSize > 0) {
-      AsciiStrnCpy(CmdLine, (CONST CHAR8*)(LinuxArguments + 1), CmdLineSize);
+      AsciiStrnCpy (CmdLine, (CONST CHAR8*)(LinuxArguments + 1), sizeof 
(CmdLine));
+      CmdLine[sizeof (CmdLine) - 1] = '\0';
     } else {
       CmdLine[0] = '\0';
     }
@@ -581,10 +582,29 @@
     if (BootOption->OptionalDataSize > 0) {
       IsPrintable = IsPrintableString (BootOption->OptionalData, &IsUnicode);
       if (IsPrintable) {
+          //
+          // The size in bytes of the string, final zero included, should
+          // be equal to or at least lower than "BootOption->OptionalDataSize"
+          // and the "IsPrintableString()" has already tested that the length
+          // in number of characters is smaller than BOOT_DEVICE_OPTION_MAX,
+          // final '\0' included. We can thus copy the string for editing
+          // using "CopyMem()". Furthermore, note that in the case of an 
Unicode
+          // string "StrnCpy()" and "StrCpy()" can not be used to copy the
+          // string because the data pointed to by "BootOption->OptionalData"
+          // is not necessarily 2-byte aligned.
+          //
         if (IsUnicode) {
-          StrnCpy (UnicodeCmdLine, BootOption->OptionalData, 
BootOption->OptionalDataSize / 2);
+          CopyMem (
+            UnicodeCmdLine, BootOption->OptionalData,
+            MIN (sizeof (UnicodeCmdLine),
+                 BootOption->OptionalDataSize)
+            );
         } else {
-          AsciiStrnCpy (CmdLine, BootOption->OptionalData, 
BootOption->OptionalDataSize);
+          CopyMem (
+            CmdLine, BootOption->OptionalData,
+            MIN (sizeof (CmdLine),
+                 BootOption->OptionalDataSize)
+            );
         }
       }
     } else {

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to