Revision: 14816
          http://sourceforge.net/p/edk2/code/14816
Author:   jcarsey
Date:     2013-10-29 16:30:25 +0000 (Tue, 29 Oct 2013)
Log Message:
-----------
ShellPkg: Properly set lasterror environment variable
- Set lasterror value based on platform width
- Use ?\226?\128?\156lasterror?\226?\128?\157 rather than 
?\226?\128?\156Lasterror?\226?\128?\157 for variable name to match Shell 
Specification
- Set lasterror value when a binary or script file is not found

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Chris Phillips <[email protected]>
Reviewed-by: Jaben Carsey <[email protected]>

Modified Paths:
--------------
    trunk/edk2/ShellPkg/Application/Shell/Shell.c

Modified: trunk/edk2/ShellPkg/Application/Shell/Shell.c
===================================================================
--- trunk/edk2/ShellPkg/Application/Shell/Shell.c       2013-10-29 11:22:39 UTC 
(rev 14815)
+++ trunk/edk2/ShellPkg/Application/Shell/Shell.c       2013-10-29 16:30:25 UTC 
(rev 14816)
@@ -1593,10 +1593,15 @@
         if (!EFI_ERROR(Status))  {
           Status = 
ShellCommandRunCommandHandler(ShellInfoObject.NewShellParametersProtocol->Argv[0],
 &ShellStatus, &LastError);
           ASSERT_EFI_ERROR(Status);
-          UnicodeSPrint(LeString, sizeof(LeString), L"0x%08Lx", ShellStatus);
-          DEBUG_CODE(InternalEfiShellSetEnv(L"DebugLasterror", LeString, 
TRUE););
+
+          if (sizeof(EFI_STATUS) == sizeof(UINT64)) {
+            UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", ShellStatus);
+          } else {
+            UnicodeSPrint(LeString, sizeof(LeString), L"0x%x", ShellStatus);
+          }
+          DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, 
TRUE););
           if (LastError) {
-            InternalEfiShellSetEnv(L"Lasterror", LeString, TRUE);
+            InternalEfiShellSetEnv(L"lasterror", LeString, TRUE);
           }
           //
           // Pass thru the exitcode from the app.
@@ -1622,6 +1627,14 @@
         }
         if (CommandWithPath == NULL || ShellIsDirectory(CommandWithPath) == 
EFI_SUCCESS) {
           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), 
ShellInfoObject.HiiHandle, ShellInfoObject.NewShellParametersProtocol->Argv[0]);
+
+          if (sizeof(EFI_STATUS) == sizeof(UINT64)) {
+            UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", EFI_NOT_FOUND);
+          } else {
+            UnicodeSPrint(LeString, sizeof(LeString), L"0x%x", EFI_NOT_FOUND);
+          }
+          DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, 
TRUE););
+          InternalEfiShellSetEnv(L"lasterror", LeString, TRUE);
         } else {
           //
           // Check if it's a NSH (script) file.
@@ -1642,11 +1655,15 @@
              );
 
             //
-            // Updatet last error status.
+            // Update last error status.
             //
-            UnicodeSPrint(LeString, sizeof(LeString), L"0x%08Lx", StatusCode);
-            DEBUG_CODE(InternalEfiShellSetEnv(L"DebugLasterror", LeString, 
TRUE););
-            InternalEfiShellSetEnv(L"Lasterror", LeString, TRUE);
+            if (sizeof(EFI_STATUS) == sizeof(UINT64)) {
+              UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", StatusCode);
+            } else {
+              UnicodeSPrint(LeString, sizeof(LeString), L"0x%x", StatusCode);
+            }
+            DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, 
TRUE););
+            InternalEfiShellSetEnv(L"lasterror", LeString, TRUE);
           }
         }
       }
@@ -1952,9 +1969,12 @@
         }
 
         if (ShellCommandGetScriptExit()) {
+          //
+          // ShellCommandGetExitCode() always returns a UINT64
+          //
           UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", 
ShellCommandGetExitCode());
-          DEBUG_CODE(InternalEfiShellSetEnv(L"DebugLasterror", LeString, 
TRUE););
-          InternalEfiShellSetEnv(L"Lasterror", LeString, TRUE);
+          DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, 
TRUE););
+          InternalEfiShellSetEnv(L"lasterror", LeString, TRUE);
 
           ShellCommandRegisterExit(FALSE, 0);
           Status = EFI_SUCCESS;

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


------------------------------------------------------------------------------
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to