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
Unknown Object (File)
Thu, Mar 12, 7:22 PM
Unknown Object (File)
Sat, Mar 7, 11:27 PM
Unknown Object (File)
Fri, Mar 6, 11:16 PM
Unknown Object (File)
Wed, Mar 4, 3:04 AM
Unknown Object (File)
Sat, Feb 28, 3:24 PM
Unknown Object (File)
Tue, Feb 24, 5:29 PM
Unknown Object (File)
Tue, Feb 24, 9:20 AM
Unknown Object (File)
Wed, Feb 18, 7:37 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