Page MenuHomeFreeBSD

date: avoid crash on invalid time
ClosedPublic

Authored by emaste on Jul 19 2017, 6:08 PM.
Tags
None
Referenced Files
F87052241: D11660.id30973.diff
Fri, Jun 28, 5:44 PM
Unknown Object (File)
Thu, Jun 27, 9:06 PM
Unknown Object (File)
Thu, Jun 27, 9:04 PM
Unknown Object (File)
Thu, Jun 27, 7:40 PM
Unknown Object (File)
Wed, Jun 26, 10:03 AM
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
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

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

bin/date/date.c
177–180

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

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

bin/date/date.c
169

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

177–180

Ok.

214–215

(See here.)

check an additional localtime for NULL return

bin/date/date.c
215

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.