]> Cypherpunks repositories - gostls13.git/commit
syscall: simplify O_TRUNC handling on Windows
authorqmuntal <quimmuntal@gmail.com>
Wed, 9 Oct 2024 08:48:07 +0000 (10:48 +0200)
committerQuim Muntal <quimmuntal@gmail.com>
Wed, 9 Oct 2024 17:23:27 +0000 (17:23 +0000)
commit18131ec8dc0db3992509f08649ae34063f00823a
treea20c9fd2dbc1896acf0fb5f869dc7fbca7ad91b1
parent0fd2d4d6c2101fb615a7546f49e92a2187191fb0
syscall: simplify O_TRUNC handling on Windows

The current implementation of O_TRUNC in syscall.Open on Windows is
prone to TOCTOU issues, as it opens the file twice if the first open
detects that the file doesn't exist. The file could
be created in between the two open calls, leading to the creation
of a new file with the undesired readonly attribute.

This CL implements O_TRUNC by just calling CreateFile once without
taking O_TRUNCATE into account, and then using Ftruncate if O_TRUNC is
set to truncate the file.

Updates #38225.

Change-Id: Ic3ad1bab75c9a1c16f99c8c5bed867c5dbc3a23b
Reviewed-on: https://go-review.googlesource.com/c/go/+/618836
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/syscall/syscall_windows.go