Page MenuHomeFreeBSD

date: avoid crash on invalid time
ClosedPublic

Authored by emaste on Jul 19 2017, 6:08 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, May 30, 7:25 AM
Unknown Object (File)
Tue, May 13, 3:31 PM
Unknown Object (File)
Apr 18 2025, 4:15 AM
Unknown Object (File)
Apr 17 2025, 11:03 AM
Unknown Object (File)
Mar 30 2025, 2:02 AM
Unknown Object (File)
Feb 23 2025, 1:44 AM
Unknown Object (File)
Feb 22 2025, 9:07 PM
Unknown Object (File)
Feb 21 2025, 10:39 PM
Subscribers
None

Details

Summary

localtime(3) returns NULL when passed an invalid time_t but date(1) previously did not handle it. Exit with an error in that case.

PR:             220828
Reported by:    Vinícius Zavam

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

bin/date/date.c
177–180 ↗(On Diff #30966)

This changes the behavior of the code in the success case. Previously we copied the struct tm and modified the local copy. Now we're modifying whatever localtime() gave us, which I suspect is some global storage?

bin/date/date.c
177–180 ↗(On Diff #30966)

Yes. Note that setthetime() already modifies the returned struct tm.

bin/date/date.c
169 ↗(On Diff #30966)

This path can also dereference the pointer returned from localtime() without checking for NULL.

177–180 ↗(On Diff #30966)

Ok.

214–215 ↗(On Diff #30966)

(See here.)

check an additional localtime for NULL return

bin/date/date.c
215 ↗(On Diff #30973)

Syntax seems wrong and ld not lt.

correct retypeo from previous upload

This revision is now accepted and ready to land.Jul 19 2017, 8:23 PM
This revision was automatically updated to reflect the committed changes.