From ed34da4007594b753ae9dffe30d5c32c7c8d98bf Mon Sep 17 00:00:00 2001 From: Robert Matthews Date: Wed, 28 Aug 2013 14:38:13 +0000 Subject: [PATCH] ShellPkg: Fix LastError environment variable truncation -Fixes LastError environment variable being truncated to 32 bits on 64 bit systems -Fixes possible buffer overrun issue with LastError string value Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Robert Matthews Reviewed-by: Jaben Carsey git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14608 6f19259b-4bc3-4df7-8a09-765794883524 --- ShellPkg/Application/Shell/Shell.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shell/Shell.c index 3df55e1a1c..3019c7d410 100644 --- a/ShellPkg/Application/Shell/Shell.c +++ b/ShellPkg/Application/Shell/Shell.c @@ -2,6 +2,7 @@ This is THE shell (application) Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.
+ Copyright (c) 2013, Hewlett-Packard Development Company, L.P. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -1359,7 +1360,7 @@ RunCommand( UINTN Argc; CHAR16 **Argv; BOOLEAN LastError; - CHAR16 LeString[11]; + CHAR16 LeString[19]; CHAR16 *PostAliasCmdLine; UINTN PostAliasSize; CHAR16 *PostVariableCmdLine; @@ -1556,7 +1557,7 @@ RunCommand( if (!EFI_ERROR(Status)) { Status = ShellCommandRunCommandHandler(ShellInfoObject.NewShellParametersProtocol->Argv[0], &ShellStatus, &LastError); ASSERT_EFI_ERROR(Status); - UnicodeSPrint(LeString, sizeof(LeString)*sizeof(LeString[0]), L"0x%08x", ShellStatus); + UnicodeSPrint(LeString, sizeof(LeString), L"0x%08Lx", ShellStatus); DEBUG_CODE(InternalEfiShellSetEnv(L"DebugLasterror", LeString, TRUE);); if (LastError) { InternalEfiShellSetEnv(L"Lasterror", LeString, TRUE); @@ -1607,7 +1608,7 @@ RunCommand( // // Updatet last error status. // - UnicodeSPrint(LeString, sizeof(LeString)*sizeof(LeString[0]), L"0x%08x", StatusCode); + UnicodeSPrint(LeString, sizeof(LeString), L"0x%08Lx", StatusCode); DEBUG_CODE(InternalEfiShellSetEnv(L"DebugLasterror", LeString, TRUE);); InternalEfiShellSetEnv(L"Lasterror", LeString, TRUE); } @@ -1909,7 +1910,7 @@ RunScriptFileHandle ( } if (ShellCommandGetScriptExit()) { - UnicodeSPrint(LeString, sizeof(LeString)*sizeof(LeString[0]), L"0x%Lx", ShellCommandGetExitCode()); + UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", ShellCommandGetExitCode()); DEBUG_CODE(InternalEfiShellSetEnv(L"DebugLasterror", LeString, TRUE);); InternalEfiShellSetEnv(L"Lasterror", LeString, TRUE); -- 2.39.2