Page MenuHomeFreeBSD

date: avoid crash on invalid time
ClosedPublic

Authored by emaste on Jul 19 2017, 6:08 PM.
Tags
None
Referenced Files
F108394145: D11660.id31001.diff
Fri, Jan 24, 10:43 AM
F108394015: D11660.id30975.diff
Fri, Jan 24, 10:42 AM
Unknown Object (File)
Sat, Dec 28, 9:43 AM
Unknown Object (File)
Dec 23 2024, 6:40 AM
Unknown Object (File)
Dec 23 2024, 1:58 AM
Unknown Object (File)
Dec 13 2024, 12:54 AM
Unknown Object (File)
Nov 18 2024, 8:55 PM
Unknown Object (File)
Nov 18 2024, 6:52 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.