]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellLevel2CommandsLib/TimeDate.c
Update code to ensure the pointer ‘CurrentName’ in function ‘PerformSingleMappingDisp...
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel2CommandsLib / TimeDate.c
index abefee3f3a4bf9c397a493a7a85b40008eb98e39..b8535139dbd4b03d8da5b49c89ee0128732c226c 100644 (file)
@@ -102,7 +102,10 @@ CheckAndSetDate (
   }\r
 \r
   Status = gRT->GetTime(&TheTime, NULL);\r
-  ASSERT_EFI_ERROR(Status);\r
+  if (EFI_ERROR(Status)) {\r
+    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN), gShellLevel2HiiHandle, L"gRT->GetTime", Status);\r
+    return (SHELL_DEVICE_ERROR);\r
+  }\r
 \r
   DateStringCopy = NULL;\r
   DateStringCopy = StrnCatGrow(&DateStringCopy, NULL, DateString, 0);\r
@@ -176,6 +179,7 @@ ShellCommandRunDate (
   EFI_TIME      TheTime;\r
   CHAR16        *ProblemParam;\r
   SHELL_STATUS  ShellStatus;\r
+  CONST CHAR16  *Param1;\r
 \r
   ShellStatus  = SHELL_SUCCESS;\r
   ProblemParam = NULL;\r
@@ -217,7 +221,10 @@ ShellCommandRunDate (
         // get the current date\r
         //\r
         Status = gRT->GetTime(&TheTime, NULL);\r
-        ASSERT_EFI_ERROR(Status);\r
+        if (EFI_ERROR(Status)) {\r
+          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN), gShellLevel2HiiHandle, L"gRT->GetTime", Status);\r
+          return (SHELL_DEVICE_ERROR);\r
+        }\r
 \r
         //\r
         // ShellPrintEx the date in SFO or regular format\r
@@ -235,9 +242,14 @@ ShellCommandRunDate (
           //\r
           // perform level 3 operation here.\r
           //\r
-          ShellStatus = CheckAndSetDate(ShellCommandLineGetRawValue(Package, 1));\r
+          Param1 = ShellCommandLineGetRawValue(Package, 1);\r
+          if (Param1 == NULL) {\r
+            ShellStatus = SHELL_INVALID_PARAMETER;\r
+          } else {\r
+            ShellStatus = CheckAndSetDate(Param1);\r
+          }\r
           if (ShellStatus != SHELL_SUCCESS) {\r
-            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, 1));\r
+            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, Param1);\r
             ShellStatus = SHELL_INVALID_PARAMETER;\r
           }\r
         }\r
@@ -303,7 +315,10 @@ CheckAndSetTime (
   }\r
 \r
   Status = gRT->GetTime(&TheTime, NULL);\r
-  ASSERT_EFI_ERROR(Status);\r
+  if (EFI_ERROR(Status)) {\r
+    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN), gShellLevel2HiiHandle, L"gRT->GetTime", Status);\r
+    return (SHELL_DEVICE_ERROR);\r
+  }\r
 \r
   if (TimeString != NULL) {\r
     TimeStringCopy = NULL;\r
@@ -369,7 +384,6 @@ ShellCommandRunTime (
 {\r
   EFI_STATUS    Status;\r
   LIST_ENTRY    *Package;\r
-  CHAR16        *Message;\r
   EFI_TIME      TheTime;\r
   CHAR16        *ProblemParam;\r
   SHELL_STATUS  ShellStatus;\r
@@ -378,13 +392,11 @@ ShellCommandRunTime (
   CONST CHAR16  *TempLocation;\r
   UINTN         TzMinutes;\r
 \r
-  ShellStatus  = SHELL_SUCCESS;\r
-  ProblemParam = NULL;\r
-\r
   //\r
   // Initialize variables\r
   //\r
-  Message = NULL;\r
+  ShellStatus  = SHELL_SUCCESS;\r
+  ProblemParam = NULL;\r
 \r
   //\r
   // initialize the shell lib (we must be in non-auto-init...)\r
@@ -414,7 +426,11 @@ ShellCommandRunTime (
     // check for "-?"\r
     //\r
     Status = gRT->GetTime(&TheTime, NULL);\r
-    ASSERT_EFI_ERROR(Status);\r
+    if (EFI_ERROR(Status)) {\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN), gShellLevel2HiiHandle, L"gRT->GetTime", Status);\r
+      return (SHELL_DEVICE_ERROR);\r
+    }\r
+\r
     if (ShellCommandLineGetFlag(Package, L"-?")) {\r
       ASSERT(FALSE);\r
     } else if (ShellCommandLineGetRawValue(Package, 2) != NULL) {\r
@@ -430,7 +446,7 @@ ShellCommandRunTime (
         //\r
         // ShellPrintEx the current time\r
         //\r
-        if (TheTime.TimeZone == 2047) {\r
+        if (TheTime.TimeZone == EFI_UNSPECIFIED_TIMEZONE) {\r
           TzMinutes = 0;\r
         } else {\r
           TzMinutes = (ABS(TheTime.TimeZone)) % 60;\r
@@ -445,13 +461,13 @@ ShellCommandRunTime (
           TheTime.Hour,\r
           TheTime.Minute,\r
           TheTime.Second,\r
-          TheTime.TimeZone==2047?L" ":(TheTime.TimeZone > 0?L"-":L"+"),\r
-          TheTime.TimeZone==2047?0:(ABS(TheTime.TimeZone)) / 60,\r
+          TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?L" ":(TheTime.TimeZone > 0?L"-":L"+"),\r
+          TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:(ABS(TheTime.TimeZone)) / 60,\r
           TzMinutes\r
          );\r
          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CRLF), gShellLevel2HiiHandle);\r
       } else if (ShellCommandLineGetFlag(Package, L"-d") && ShellCommandLineGetValue(Package, L"-d") == NULL) {\r
-        if (TheTime.TimeZone == 2047) {\r
+        if (TheTime.TimeZone == EFI_UNSPECIFIED_TIMEZONE) {\r
           TzMinutes = 0;\r
         } else {\r
           TzMinutes = (ABS(TheTime.TimeZone)) % 60;\r
@@ -466,8 +482,8 @@ ShellCommandRunTime (
           TheTime.Hour,\r
           TheTime.Minute,\r
           TheTime.Second,\r
-          TheTime.TimeZone==2047?L" ":(TheTime.TimeZone > 0?L"-":L"+"),\r
-          TheTime.TimeZone==2047?0:(ABS(TheTime.TimeZone)) / 60,\r
+          TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?L" ":(TheTime.TimeZone > 0?L"-":L"+"),\r
+          TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:(ABS(TheTime.TimeZone)) / 60,\r
           TzMinutes\r
          );\r
           switch (TheTime.Daylight) {\r
@@ -500,7 +516,7 @@ ShellCommandRunTime (
             } else {\r
               Tz = (INT16)ShellStrToUintn(TempLocation);\r
             }\r
-            if (!(Tz >= -1440 && Tz <= 1440) && Tz != 2047) {\r
+            if (!(Tz >= -1440 && Tz <= 1440) && Tz != EFI_UNSPECIFIED_TIMEZONE) {\r
               ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellLevel2HiiHandle, L"-tz");\r
               ShellStatus = SHELL_INVALID_PARAMETER;\r
             }\r
@@ -633,10 +649,16 @@ CheckAndSetTimeZone (
   }\r
 \r
   Status = gRT->GetTime(&TheTime, NULL);\r
-  ASSERT_EFI_ERROR(Status);\r
+  if (EFI_ERROR(Status)) {\r
+    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN), gShellLevel2HiiHandle, L"gRT->GetTime", Status);\r
+    return (SHELL_DEVICE_ERROR);\r
+  }\r
 \r
   TimeZoneCopy = NULL;\r
   TimeZoneCopy = StrnCatGrow(&TimeZoneCopy, NULL, TimeZoneString, 0);\r
+  if (TimeZoneCopy == NULL) {\r
+    return (SHELL_OUT_OF_RESOURCES);\r
+  }\r
   Walker = TimeZoneCopy;\r
   Walker2 = StrStr(Walker, L":");\r
   if (Walker2 != NULL && *Walker2 == L':') {\r
@@ -645,7 +667,7 @@ CheckAndSetTimeZone (
   if (*Walker == L'-') {\r
     TheTime.TimeZone = (INT16)((ShellStrToUintn (++Walker)) * 60);\r
   } else {\r
-    TheTime.TimeZone = (INT16)((ShellStrToUintn (Walker)) * -60);\r
+    TheTime.TimeZone = (INT16)((INT16)(ShellStrToUintn (Walker)) * -60);\r
   }\r
   if (Walker2 != NULL) {\r
     Walker = Walker2 + 1;\r
@@ -717,10 +739,10 @@ ShellCommandRunTimeZone (
   // parse the command line\r
   //\r
   if (PcdGet8(PcdShellSupportLevel) == 2) {\r
-    Status = ShellCommandLineParse (TimeZoneParamList2, &Package, &ProblemParam, FALSE);\r
+    Status = ShellCommandLineParse (TimeZoneParamList2, &Package, &ProblemParam, TRUE);\r
   } else {\r
     ASSERT(PcdGet8(PcdShellSupportLevel) == 3);\r
-    Status = ShellCommandLineParseEx (TimeZoneParamList3, &Package, &ProblemParam, FALSE, TRUE);\r
+    Status = ShellCommandLineParseEx (TimeZoneParamList3, &Package, &ProblemParam, TRUE, TRUE);\r
   }\r
   if (EFI_ERROR(Status)) {\r
     if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r
@@ -774,9 +796,12 @@ ShellCommandRunTimeZone (
       // Get Current Time Zone Info\r
       //\r
       Status = gRT->GetTime(&TheTime, NULL);\r
-      ASSERT_EFI_ERROR(Status);\r
+      if (EFI_ERROR(Status)) {\r
+        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN), gShellLevel2HiiHandle, L"gRT->GetTime", Status);\r
+        return (SHELL_DEVICE_ERROR);\r
+      }\r
 \r
-      if (TheTime.TimeZone != 2047) {\r
+      if (TheTime.TimeZone != EFI_UNSPECIFIED_TIMEZONE) {\r
         Found = FALSE;\r
         for ( LoopVar = 0\r
             ; LoopVar < sizeof(TimeZoneList) / sizeof(TimeZoneList[0])\r
@@ -792,7 +817,7 @@ ShellCommandRunTimeZone (
               //\r
               // Print basic info only\r
               //\r
-              if (TheTime.TimeZone == 2047) {\r
+              if (TheTime.TimeZone == EFI_UNSPECIFIED_TIMEZONE) {\r
                 TzMinutes = 0;\r
               } else {\r
                 TzMinutes = (ABS(TheTime.TimeZone)) % 60;\r
@@ -804,8 +829,8 @@ ShellCommandRunTimeZone (
                 NULL,\r
                 STRING_TOKEN(STR_TIMEZONE_SIMPLE),\r
                 gShellLevel2HiiHandle,\r
-                TheTime.TimeZone==2047?0:(TheTime.TimeZone > 0?L"-":L"+"),\r
-                TheTime.TimeZone==2047?0:(ABS(TheTime.TimeZone)) / 60,\r
+                TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:(TheTime.TimeZone > 0?L"-":L"+"),\r
+                TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:(ABS(TheTime.TimeZone)) / 60,\r
                 TzMinutes);\r
             }\r
             Found = TRUE;\r
@@ -816,7 +841,7 @@ ShellCommandRunTimeZone (
           //\r
           // Print basic info only\r
           //\r
-          if (TheTime.TimeZone == 2047) {\r
+          if (TheTime.TimeZone == EFI_UNSPECIFIED_TIMEZONE) {\r
             TzMinutes = 0;\r
           } else {\r
             TzMinutes = (ABS(TheTime.TimeZone)) % 60;\r
@@ -827,8 +852,8 @@ ShellCommandRunTimeZone (
             NULL,\r
             STRING_TOKEN(STR_TIMEZONE_SIMPLE),\r
             gShellLevel2HiiHandle,\r
-            TheTime.TimeZone==2047?0:(TheTime.TimeZone > 0?L"-":L"+"),\r
-            TheTime.TimeZone==2047?0:(ABS(TheTime.TimeZone)) / 60,\r
+            TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:(TheTime.TimeZone > 0?L"-":L"+"),\r
+            TheTime.TimeZone==EFI_UNSPECIFIED_TIMEZONE?0:(ABS(TheTime.TimeZone)) / 60,\r
             TzMinutes);\r
           if (ShellCommandLineGetFlag(Package, L"-f")) {\r
             ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN(STR_TIMEZONE_NI), gShellLevel2HiiHandle);\r
@@ -836,7 +861,7 @@ ShellCommandRunTimeZone (
         }\r
       } else {\r
         //\r
-        // TimeZone was 2047 (unknown) from GetTime()\r
+        // TimeZone was EFI_UNSPECIFIED_TIMEZONE (unknown) from GetTime()\r
         //\r
       }\r
     }\r