public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Long Qin <qin.long@intel.com>
To: edk2-devel@lists.01.org
Cc: star.zeng@intel.com, ting.ye@intel.com, Qin Long <qin.long@intel.com>
Subject: [PATCH] CryptoPkg/BaseCryptLib: Add error handling for time() wrapper
Date: Fri, 19 Jan 2018 15:05:06 +0800	[thread overview]
Message-ID: <20180119070506.5980-1-qin.long@intel.com> (raw)

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>
---
 CryptoPkg/Library/BaseCryptLib/SysCall/TimerWrapper.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/CryptoPkg/Library/BaseCryptLib/SysCall/TimerWrapper.c b/CryptoPkg/Library/BaseCryptLib/SysCall/TimerWrapper.c
index 581b8fb028..95e0419640 100644
--- a/CryptoPkg/Library/BaseCryptLib/SysCall/TimerWrapper.c
+++ b/CryptoPkg/Library/BaseCryptLib/SysCall/TimerWrapper.c
@@ -72,14 +72,18 @@ UINTN CumulativeDays[2][14] = {
 //  )
 time_t time (time_t *timer)
 {
-  EFI_TIME  Time;
-  time_t    CalTime;
-  UINTN     Year;
+  EFI_STATUS  Status;
+  EFI_TIME    Time;
+  time_t      CalTime;
+  UINTN       Year;
 
   //
   // Get the current time and date information
   //
-  gRT->GetTime (&Time, NULL);
+  Status = gRT->GetTime (&Time, NULL);
+  if (EFI_ERROR (Status) || (Time.Year < 1970)) {
+    return 0;
+  }
 
   //
   // Years Handling
-- 
2.15.1.windows.2



             reply	other threads:[~2018-01-19  7:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-19  7:05 Long Qin [this message]
2018-01-19  7:10 ` [PATCH] CryptoPkg/BaseCryptLib: Add error handling for time() wrapper Zeng, Star
2018-01-19  7:12   ` Long, Qin
2018-01-19  7:14     ` Zeng, Star
2018-01-19  7:15       ` Ni, Ruiyu
2018-01-19  7:21         ` Long, Qin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180119070506.5980-1-qin.long@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox