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, Dec 13, 12:54 AM
Unknown Object (File)
Nov 18 2024, 8:55 PM
Unknown Object (File)
Nov 18 2024, 6:52 PM
Unknown Object (File)
Sep 10 2024, 9:29 PM
Unknown Object (File)
Sep 8 2024, 2:21 PM
Unknown Object (File)
Sep 8 2024, 5:31 AM
Unknown Object (File)
Sep 8 2024, 2:05 AM
Unknown Object (File)
Sep 7 2024, 3:23 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.