]> git.proxmox.com Git - mirror_edk2.git/commitdiff
CryptoPkg: Fix the potential system hang issue
authorJiaxin Wu <jiaxin.wu@intel.com>
Fri, 11 Mar 2016 03:02:00 +0000 (11:02 +0800)
committerJiaxin Wu <jiaxin.wu@intel.com>
Tue, 15 Mar 2016 01:04:20 +0000 (09:04 +0800)
This patch is used to fix the potential system hang
caused by the NULL 'time' parameter usage.

Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Long Qin <qin.long@intel.com>
Cc: Ye Ting <ting.ye@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com>
Reviewed-by: David Woodhouse <David.Woodhouse@intel.com>
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