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)
Sun, Jun 23, 11:28 PM
Unknown Object (File)
Sun, Jun 23, 9:46 AM
Unknown Object (File)
Sat, Jun 22, 9:53 AM
Unknown Object (File)
Fri, Jun 21, 7:53 AM
Unknown Object (File)
Thu, Jun 20, 8:29 PM
Unknown Object (File)
Thu, Jun 20, 1:00 PM
Unknown Object (File)
May 16 2024, 5:14 AM
Unknown Object (File)
May 16 2024, 5:14 AM
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.