From: Olivier Martin Date: Wed, 19 Jun 2013 18:00:46 +0000 (+0000) Subject: ArmPlatformPkg/Bds: Moved the PrintLib() after forcing the last character to be null X-Git-Tag: edk2-stable201903~12476 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=40761653599e4be2c4fa38cd002033e3458786e4;p=mirror_edk2.git ArmPlatformPkg/Bds: Moved the PrintLib() after forcing the last character to be null That should prevent the risk of buffer overflow. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Olivier Martin git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14430 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/ArmPlatformPkg/Bds/BdsHelper.c b/ArmPlatformPkg/Bds/BdsHelper.c index fa3026c8ff..9747b3fbd3 100644 --- a/ArmPlatformPkg/Bds/BdsHelper.c +++ b/ArmPlatformPkg/Bds/BdsHelper.c @@ -29,13 +29,13 @@ EditHIInputStr ( // The command line must be at least one character long ASSERT (MaxCmdLine > 0); - Print (CmdLine); - // Ensure the last character of the buffer is the NULL character CmdLine[MaxCmdLine - 1] = '\0'; + Print (CmdLine); + // To prevent a buffer overflow, we only allow to enter (MaxCmdLine-1) characters - for (CmdLineIndex = StrLen (CmdLine); CmdLineIndex < MaxCmdLine-1; ) { + for (CmdLineIndex = StrLen (CmdLine); CmdLineIndex < MaxCmdLine - 1; ) { Status = gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &WaitIndex); ASSERT_EFI_ERROR (Status);