CryptoPkg: Fix the potential system hang issue

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>
This commit is contained in:
Jiaxin Wu 2016-03-11 11:02:00 +08:00
parent 727894d5c9
commit 5e2318dd37
1 changed files with 16 additions and 11 deletions

View File

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