mirror of
https://git.openafs.org/openafs.git
synced 2025-01-31 05:27:44 +00:00
localtime can return NULL if unable to read system clock
This adds checks for some invocations of localtime() to avoid possible NULL dereference. (via facebook-infer) Change-Id: I2b779d8f60c032563eb4ee3cebe20b14afbb0fa3 Reviewed-on: https://gerrit.openafs.org/13206 Reviewed-by: Michael Meffie <mmeffie@sinenomine.net> Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
This commit is contained in:
parent
ec45ae6053
commit
4898be6278
@ -28,9 +28,13 @@ pr_TimeToString(time_t clock)
|
||||
if (!this_year) {
|
||||
time_t now = time(0);
|
||||
tm = localtime(&now);
|
||||
if (!tm)
|
||||
return "time-not-set ";
|
||||
this_year = tm->tm_year;
|
||||
}
|
||||
tm = localtime(&clock);
|
||||
if (!tm)
|
||||
return "time-not-set ";
|
||||
if (tm->tm_year != this_year)
|
||||
strftime(buffer, 32, "%m/%d/%Y %H:%M:%S", tm);
|
||||
else
|
||||
|
@ -390,6 +390,8 @@ ktime_next(struct ktime * aktime, afs_int32 afrom)
|
||||
* daylight savings time day */
|
||||
for (probe = start;; probe += (23 * 3600)) {
|
||||
tsp = localtime(&probe); /* find out what UTC time "probe" is */
|
||||
if (!tsp)
|
||||
return KTIME_NEVERTIME;
|
||||
|
||||
tdate.year = tsp->tm_year;
|
||||
tdate.month = tsp->tm_mon + 1;
|
||||
@ -405,7 +407,10 @@ ktime_next(struct ktime * aktime, afs_int32 afrom)
|
||||
continue; /* "probe" time is already past */
|
||||
if ((tmask & KTIME_DAY) == 0) /* don't care about day, we're done */
|
||||
break;
|
||||
|
||||
tsp = localtime(&time_next);
|
||||
if (!tsp)
|
||||
return KTIME_NEVERTIME;
|
||||
if (tsp->tm_wday == aktime->day)
|
||||
break; /* day matches, we're done */
|
||||
}
|
||||
@ -637,6 +642,8 @@ ktime_InterpretDate(struct ktime_date * akdate)
|
||||
while (tbit > 0) {
|
||||
temp = tresult + tbit; /* see if adding this bit keeps us < akdate */
|
||||
tsp = localtime(&temp);
|
||||
if (!tsp)
|
||||
return KTIMEDATE_NEVERDATE;
|
||||
tsp->tm_mon++;
|
||||
if (KDateCmp(akdate, tsp) >= 0) {
|
||||
/* if temp still represents earlier than date than we're searching
|
||||
|
Loading…
x
Reference in New Issue
Block a user