Page MenuHomeFreeBSD

touch: Fix setting time of created file if fstat() fails
ClosedPublic

Authored by obiwac on Feb 4 2026, 9:20 PM.
Tags
None
Referenced Files
F168183617: D55117.id171207.diff
Wed, Aug 26, 6:33 PM
Unknown Object (File)
Sat, Aug 22, 4:00 PM
Unknown Object (File)
Tue, Aug 18, 7:47 AM
Unknown Object (File)
Mon, Aug 17, 11:14 PM
Unknown Object (File)
Fri, Aug 14, 8:09 AM
Unknown Object (File)
Thu, Aug 13, 1:50 PM
Unknown Object (File)
Thu, Aug 13, 1:46 PM
Unknown Object (File)
Mon, Aug 10, 9:58 PM
Subscribers

Details

Summary

Previously, if creating the file and fstat() fails, we would've ended up
calling utimensat() on that file anyways with whatever was in sb.

Not that this is an error likely to happen...

We don't check for the return value of close() as we aren't writing
anything to the file and the file is created on success of open().

Fixes: cb54c500d0e1 ("touch: don't leak descriptor if fstat(2) fails")
Sponsored by: Klara, Inc.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable