]> git.proxmox.com Git - mirror_edk2.git/commitdiff
CryptoPkg/BaseCryptLib: Add error handling for time() wrapper
authorLong Qin <qin.long@intel.com>
Mon, 22 Jan 2018 06:27:53 +0000 (14:27 +0800)
committerLong Qin <qin.long@intel.com>
Mon, 22 Jan 2018 06:28:15 +0000 (14:28 +0800)
In time() wrapper implementation, the gRT->GetTime() call may be not
available. This patch adds the extra error handling to avoid the
potential dead loop.

Cc: Star Zeng <star.zeng@intel.com>
Cc: Ting Ye <ting.ye@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Qin Long <qin.long@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
CryptoPkg/Library/BaseCryptLib/SysCall/TimerWrapper.c

index 581b8fb02809f2bc45f9cf3c65d503d258508c0d..cdf3b60b9f82aa525d48db70ed548f0e5b951095 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 - 2017, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2010 - 2018, 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
@@ -72,14 +72,18 @@ UINTN CumulativeDays[2][14] = {
 //  )\r
 time_t time (time_t *timer)\r
 {\r
-  EFI_TIME  Time;\r
-  time_t    CalTime;\r
-  UINTN     Year;\r
+  EFI_STATUS  Status;\r
+  EFI_TIME    Time;\r
+  time_t      CalTime;\r
+  UINTN       Year;\r
 \r
   //\r
   // Get the current time and date information\r
   //\r
-  gRT->GetTime (&Time, NULL);\r
+  Status = gRT->GetTime (&Time, NULL);\r
+  if (EFI_ERROR (Status) || (Time.Year < 1970)) {\r
+    return 0;\r
+  }\r
 \r
   //\r
   // Years Handling\r