]> git.proxmox.com Git - mirror_edk2.git/blobdiff - CryptoPkg/Library/BaseCryptLib/SysCall/TimerWrapper.c
CryptoPkg: Fix the potential system hang issue
[mirror_edk2.git] / CryptoPkg / Library / BaseCryptLib / SysCall / TimerWrapper.c
index 6422d610f3bd7976b233bae69b87bc7cf1e3d0c1..93e487dcefc3968e7c5a72b1692ae2cc8b45c1a8 100644 (file)
@@ -2,7 +2,7 @@
   C Run-Time Libraries (CRT) Time Management Routines Wrapper Implementation\r
   for OpenSSL-based Cryptographic Library (used in DXE & RUNTIME).\r
 \r
-Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -73,6 +73,7 @@ UINTN CumulativeDays[2][14] = {
 time_t time (time_t *timer)\r
 {\r
   EFI_TIME  Time;\r
+  time_t    CalTime;\r
   UINTN     Year;\r
 \r
   //\r
@@ -84,22 +85,26 @@ time_t time (time_t *timer)
   // Years Handling\r
   // UTime should now be set to 00:00:00 on Jan 1 of the current year.\r
   //\r
-  for (Year = 1970, *timer = 0; Year != Time.Year; Year++) {\r
-    *timer = *timer + (time_t)(CumulativeDays[IsLeap(Year)][13] * SECSPERDAY);\r
+  for (Year = 1970, CalTime = 0; Year != Time.Year; Year++) {\r
+    CalTime = CalTime + (time_t)(CumulativeDays[IsLeap(Year)][13] * SECSPERDAY);\r
   }\r
 \r
   //\r
   // Add in number of seconds for current Month, Day, Hour, Minute, Seconds, and TimeZone adjustment\r
   //\r
-  *timer = *timer + \r
-           (time_t)((Time.TimeZone != EFI_UNSPECIFIED_TIMEZONE) ? (Time.TimeZone * 60) : 0) +\r
-           (time_t)(CumulativeDays[IsLeap(Time.Year)][Time.Month] * SECSPERDAY) + \r
-           (time_t)(((Time.Day > 0) ? Time.Day - 1 : 0) * SECSPERDAY) + \r
-           (time_t)(Time.Hour * SECSPERHOUR) + \r
-           (time_t)(Time.Minute * 60) + \r
-           (time_t)Time.Second;\r
-\r
-  return *timer;\r
+  CalTime = CalTime + \r
+            (time_t)((Time.TimeZone != EFI_UNSPECIFIED_TIMEZONE) ? (Time.TimeZone * 60) : 0) +\r
+            (time_t)(CumulativeDays[IsLeap(Time.Year)][Time.Month] * SECSPERDAY) + \r
+            (time_t)(((Time.Day > 0) ? Time.Day - 1 : 0) * SECSPERDAY) + \r
+            (time_t)(Time.Hour * SECSPERHOUR) + \r
+            (time_t)(Time.Minute * 60) + \r
+            (time_t)Time.Second;\r
+\r
+  if (timer != NULL) {\r
+    *timer = CalTime;\r
+  }\r
+\r
+  return CalTime;\r
 }\r
 \r
 //\r