]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPlatformPkg/Bds: stop inputting more characters when string is full
authorRyan Harkin <ryan.harkin@linaro.org>
Wed, 12 Mar 2014 17:24:48 +0000 (17:24 +0000)
committeroliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 12 Mar 2014 17:24:48 +0000 (17:24 +0000)
If EditHIInputStr() is called, say with a MaxCmdLine of 2, the user is
currently allowed to enter 2 characters.

If the second character is a carriage return/line feed, this is
substituted with a NULL and the function returns.

If the second character is a regular character, the loop terminated and
the function returns.  However, the buffer has not been NULL terminated.

This patch prevents the user from entering a regular character as the
final character and ensures that the only way out of the input is by
pressing ESC or ENTER (or equivalent).

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ryan Harkin <ryan.harkin@linaro.org>
Reviewed-by: Olivier Martin <olivier.martin@arm.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15325 6f19259b-4bc3-4df7-8a09-765794883524

ArmPlatformPkg/Bds/BdsHelper.c

index 3142d85c10cdf46cdecbdd7f155712782f0f6ab3..1c233d76c594a36a5ce6202cb4360319118bcd87 100644 (file)
@@ -35,7 +35,7 @@ EditHIInputStr (
   Print (CmdLine);\r
 \r
   // To prevent a buffer overflow, we only allow to enter (MaxCmdLine-1) characters\r
   Print (CmdLine);\r
 \r
   // To prevent a buffer overflow, we only allow to enter (MaxCmdLine-1) characters\r
-  for (CmdLineIndex = StrLen (CmdLine); CmdLineIndex < MaxCmdLine - 1; ) {\r
+  for (CmdLineIndex = StrLen (CmdLine); CmdLineIndex < MaxCmdLine; ) {
     Status = gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &WaitIndex);\r
     ASSERT_EFI_ERROR (Status);\r
 \r
     Status = gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &WaitIndex);\r
     ASSERT_EFI_ERROR (Status);\r
 \r
@@ -62,7 +62,7 @@ EditHIInputStr (
       }\r
     } else if ((Key.ScanCode == SCAN_ESC) || (Char == 0x1B) || (Char == 0x0)) {\r
       return EFI_INVALID_PARAMETER;\r
       }\r
     } else if ((Key.ScanCode == SCAN_ESC) || (Char == 0x1B) || (Char == 0x0)) {\r
       return EFI_INVALID_PARAMETER;\r
-    } else {\r
+    } else if (CmdLineIndex < (MaxCmdLine-1)) {
       CmdLine[CmdLineIndex++] = Key.UnicodeChar;\r
       Print (L"%c", Key.UnicodeChar);\r
     }\r
       CmdLine[CmdLineIndex++] = Key.UnicodeChar;\r
       Print (L"%c", Key.UnicodeChar);\r
     }\r
@@ -187,9 +187,7 @@ GetHIInputBoolean (
 \r
   while(1) {\r
     Print (L"[y/n] ");\r
 \r
   while(1) {\r
     Print (L"[y/n] ");\r
-    // Set MaxCmdLine to 3 to give space for carriage return (when the user\r
-    // hits enter) and terminal '\0'.\r
-    Status = GetHIInputStr (CmdBoolean, 3);\r
+    Status = GetHIInputStr (CmdBoolean, 2);
     if (EFI_ERROR(Status)) {\r
       return Status;\r
     } else if ((CmdBoolean[0] == L'y') || (CmdBoolean[0] == L'Y')) {\r
     if (EFI_ERROR(Status)) {\r
       return Status;\r
     } else if ((CmdBoolean[0] == L'y') || (CmdBoolean[0] == L'Y')) {\r