aboutsummaryrefslogtreecommitdiff
path: root/src/os
AgeCommit message (Collapse)Author
22 hoursos/exec: doc typoWeixie Cui
Change-Id: I623eee6738a8ebb1db2bc5693a9973c58878260c GitHub-Last-Rev: d7d918d4ede9d7a374a0a51f569c6890d74c8f91 GitHub-Pull-Request: golang/go#78609 Reviewed-on: https://go-review.googlesource.com/c/go/+/764364 Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Sean Liao <sean@liao.dev>
34 hoursos/exec: use argv() to avoid panic inside of Cmd.String()Neal Patel
A surprisingly non-zero amount of direct uses Cmd make this panic possible. Change-Id: If86cabfb0f7c0250e2a5aa3fcaba367de5d10ca4 Reviewed-on: https://go-review.googlesource.com/c/go/+/765680 Reviewed-by: Ian Lance Taylor <iant@golang.org> Auto-Submit: Neal Patel <nealpatel@google.com> TryBot-Bypass: Nicholas Husin <nsh@golang.org> Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Nicholas Husin <nsh@golang.org> Reviewed-by: Keith Randall <khr@google.com>
9 daysos: use t.TempDir in root_test tempDirWithUnixSocketRunxi Yu
tempDirWithUnixSocket used os.MkdirTemp("", ""), while other paths in root consistency tests use t.TempDir(). If GOTMPDIR and the system temp dir are on different filesystems (such as during abuild), TestRootConsistencyRename and TestRootConsistencyLink may produce EXDEV. Fixes #78063 Change-Id: Ib81abec0876babf0cc0e2d9e53e34f051ddfbbc6 Reviewed-on: https://go-review.googlesource.com/c/go/+/754102 Auto-Submit: Sean Liao <sean@liao.dev> Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Sean Liao <sean@liao.dev> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com>
2026-03-30all: fix some minor issues in the commentscuishuang
Change-Id: If6c304efac7a46a9718cdc63ded3d98a26a3a831 Reviewed-on: https://go-review.googlesource.com/c/go/+/760700 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Robert Griesemer <gri@google.com> Reviewed-by: Neal Patel <nealpatel@google.com> Reviewed-by: Fred Sauer <fredsa@google.com> Reviewed-by: Junyang Shao <shaojunyang@google.com> Reviewed-by: Robert Griesemer <gri@google.com>
2026-03-17os/exec: document that Cmd.Wait must not be called concurrentlyBasavaraj PB
Clarify in the Wait documentation that it must not be called concurrently from multiple goroutines. Also note that a custom Cmd.Cancel function should not call Wait because Cancel may be invoked by watchCtx in a separate goroutine. Fixes #78046 Change-Id: I5c0ebc41bd3c39c78f3b37539c59cdfedfd90e72 Reviewed-on: https://go-review.googlesource.com/c/go/+/753602 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Carlos Amedee <carlos@golang.org> Auto-Submit: Ian Lance Taylor <iant@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Mark Freeman <markfreeman@google.com>
2026-03-10os: allow EPERM during TestGetwdDeepRuss Cox
Change-Id: Iceadf12f4211eb58dd10dceeca7e68ec228aee61 Reviewed-on: https://go-review.googlesource.com/c/go/+/752900 Auto-Submit: Russ Cox <rsc@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Robert Griesemer <gri@google.com>
2026-02-26os: avoid escape from Root via ReadDir or ReaddirDamien Neil
When reading the contents of a directory using File.ReadDir or File.Readdir, the os.FileInfo was populated on Unix platforms using lstat. This lstat call is vulnerable to a TOCTOU race and could escape the root. For example: - Open the directory "dir" within a Root. This directory contains a file named "file". - Use File.ReadDir to list the contents of "dir", receiving a os.DirEntry for "dir/file". - Replace "dir" with a symlink to "/etc". - Use DirEntry.Info to retrieve the FileInfo for "dir/file". This FileInfo contains information on "/etc/file" instead. This escape permits identifying the presence or absence of files outside a Root, as well as retreiving stat metadata (size, mode, modification time, etc.) for files outside a Root. This escape does not permit reading or writing to files outside a Root. Fixes #77827 Fixes CVE-2026-27139 Change-Id: I40004f830c588e516aff8ee593d630d36a6a6964 Reviewed-on: https://go-review.googlesource.com/c/go/+/749480 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Nicholas Husin <husin@google.com> Reviewed-by: Nicholas Husin <nsh@golang.org> Auto-Submit: Damien Neil <dneil@google.com>
2026-02-24os/signal: completely ignore bogus signalsMichael Pratt
signal.Notify should ignore bogus signals (syscall.Signals with invalid signal numbers). Ignoring means Notify/Stop/Reset all work fine, but the channel will never receive any events. Today, Stop hangs if Notify has only ever been called with bogus signals because Stop assumes that runtime.signal_recv is running if a handler is present. Notify unconditionally registers the handler, but only starts signal_recv if the signal was valid. Address this by avoiding registering the handler at all if the signal is bogus. We additionally add a bogus signal check to cancel (used by Ignore/Reset). Currently those are calling into the runtime signal_ignore and signal_disable, which do ignore bogus signals, but is now inconsistent with the rest of the package. For #77076. Change-Id: I6a6a636c27c41a158e203bbf470be5f1f3f631bd Reviewed-on: https://go-review.googlesource.com/c/go/+/735040 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Auto-Submit: Michael Pratt <mpratt@google.com>
2026-02-11internal/poll: avoid race between execIO and DisassociateIOCPqmuntal
This is a step towards deferring adding the handle to IOCP until the first IO operation. There is a small race windows between execIO and DisassociateIOCP where execIO checks if the fd is disassociated before passing the operation to the OS. DisassociateIOCP can set the disassociated flag right after that check but before Windows started processing the IO operation. Once Windows takes over, the race doesn't matter anymore because Windows doesn't allow disassociating a handle that has pending IO operations. If that still hasn't happened, an overlapped IO operation will start assuming the they can be waited using the Go runtime IOCP, which is wrong due to the disassociation, leading to undefined behavior. Fix that race by trying to take a write/read lock in DisassociateIOCP before setting the disassociated flag, but failing if there is an ongoing execIO operation so that DisassociateIOCP doesn't block indefinitely waiting for execIO to finish. For #76391 Cq-Include-Trybots: luci.golang.try:gotip-windows-amd64-longtest,gotip-windows-amd64-race Change-Id: Iec265fa1900383aace50051d2be750bc76aa0944 Reviewed-on: https://go-review.googlesource.com/c/go/+/741020 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2026-02-03internal/poll: readWriteUnlock should destroy fd when no remaining referencesqmuntal
Fixes #77404 Change-Id: I0402becb94855baf942d6ba3815cc2a3c1526d6e Reviewed-on: https://go-review.googlesource.com/c/go/+/740921 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2026-01-27os/exec: document blocking Stdin/Stdout/StderrIan Lance Taylor
WaitDelay only handles writes to Stdin and reads from Stdout/Stderr. If Stdin is set to a blocking Reader, or Stdout/Stderr are set to a blocking Writer, Wait can hang indefinitely. I don't see any way to fix this with the current API, as there is no general way that the os/exec package can interrupt the blocking Read or Write. This CL documents the limitation and points people toward the workaround of using StdinPipe/StdoutPipe/StderrPipe and arranging for their own way to interrupt the blocking Read or Write. Fixes #77227 Change-Id: I3150ae7af89dccf8d859b41eb43eaf0bbbb55fee Reviewed-on: https://go-review.googlesource.com/c/go/+/739422 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Sean Liao <sean@liao.dev> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Carlos Amedee <carlos@golang.org>
2026-01-12os/exec: move platform-specific LookPath docs to a common commentDamien Neil
We have four different LookPath variations (unix, windows, plan9, wasm), each with slightly different doc comments. Unify the documentation and move it to a single, common LookPath. Change-Id: I56bae57e80887a73ef0f6933258ee0a48dbccdcf Reviewed-on: https://go-review.googlesource.com/c/go/+/734320 Reviewed-by: Roland Shoemaker <roland@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2026-01-12os/exec_test: fix test on Plan 9Ori Bernstein
Error strings vary across OSes when trying to execute a file that does not exist. Since matching them is not the point of the test, ignore them. Fixes #76965 Change-Id: I6d220bc2d0289070f3441adb48983c13b2a3e597 Reviewed-on: https://go-review.googlesource.com/c/go/+/732940 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Richard Miller <millerresearch@gmail.com> Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Alan Donovan <adonovan@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2026-01-06os/exec: avoid atomic.Bool for Cmd.startCalledAlan Donovan
An atomic.Bool isn't necessary here since, unless otherwise specified, the methods of an object are not concurrency-safe w.r.t. each other. Using an atomic causes the copylocks vet check to warn about copying of Cmd, which is not wrong, because one shouldn't be copying opaque complex structs from other packages, but it is a nuisance in the absence of any safe way to copy a Cmd. If and when we add a Clone method to Cmd (see #77075) then it would be appropriate to revert this change so that we get the benefit of the static check (though ideally we would make a more explicit tool-readable declaration of the "do not copy" attribute than merely happening to use an atomic.Bool). For #77075 Change-Id: I982d4e86623ca165a3e76bbf648fd44041d5f6bb Reviewed-on: https://go-review.googlesource.com/c/go/+/734200 Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-12-22os/exec: second call to Cmd.Start is always an errorAlan Donovan
Previously it would return an error only if the first call resulted in process creation, contra the intent of the comment at exec.Cmd: // A Cmd cannot be reused after calling its [Cmd.Start], [Cmd.Run], // [Cmd.Output], or [Cmd.CombinedOutput] methods. Also, clear the Cmd.goroutines slice in case of failure to start a process, so that the closures can be GC'd and their pipe fds finalized and closed. Fixes #76746 Change-Id: Ic63a4dced0aa52c2d4be7d44f6dcfc84ee22282c Reviewed-on: https://go-review.googlesource.com/c/go/+/728642 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com>
2025-11-26os: allow direntries to have zero inodes on LinuxDave Vasilevsky
Some Linux filesystems have been known to return valid enties with zero inodes. This new behavior also puts Go in agreement with recent glibc. Fixes #76428 Change-Id: Ieaf50739a294915a3ea2ef8c5a3bb2a91a186881 GitHub-Last-Rev: 8f83d009ef0320fd3fe7cf03e55d5d24df57f015 GitHub-Pull-Request: golang/go#76448 Reviewed-on: https://go-review.googlesource.com/c/go/+/724220 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-11-26os,internal/syscall/windows: support O_* flags in Root.OpenFileqmuntal
These file flags are supported by os.OpenFile since CL 699415. Closes #73676 Change-Id: Ib37102a565f538d394d2a94bd605d6c6004f3028 Reviewed-on: https://go-review.googlesource.com/c/go/+/724621 Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-11-26os,internal/poll: don't call IsNonblock for consoles and Stdinqmuntal
windows.IsNonblock can block for synchronous handles that have an outstanding I/O operation. Console handles are always synchronous, so we should not call IsNonblock for them. Stdin is often a pipe, and almost always a synchronous handle, so we should not call IsNonblock for it either. This avoids potential deadlocks during os package initialization, which calls NewFile(syscall.Stdin). Fixes #75949 Updates #76391 Cq-Include-Trybots: luci.golang.try:gotip-windows-amd64-longtest,gotip-windows-amd64-race,gotip-windows-arm64 Change-Id: I1603932b0a99823019aa0cad960f94cee9996505 Reviewed-on: https://go-review.googlesource.com/c/go/+/724640 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-11-20os/signal: make NotifyContext cancel the context with a causeFilippo Valsorda
This is especially useful when combined with the nesting semantics of context.Cause, and with errgroup's use of CancelCauseFunc. For example, with the following code ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt) defer stop() serveGroup, ctx := errgroup.WithContext(ctx) calling context.Cause(ctx) after serveGroup.Wait() will return either "interrupt signal received" (if that happens first) or the error from serveGroup. Change-Id: Ie181f5f84269f6e39defdad2d5fd8ead6a6a6964 Reviewed-on: https://go-review.googlesource.com/c/go/+/721700 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Mark Freeman <markfreeman@google.com> Reviewed-by: Sean Liao <sean@liao.dev> Auto-Submit: Filippo Valsorda <filippo@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Commit-Queue: Junyang Shao <shaojunyang@google.com> Reviewed-by: Junyang Shao <shaojunyang@google.com>
2025-11-14std: fix printf("%q", int) mistakesAlan Donovan
For #72850 Change-Id: I07e64f05c82a34b1dadb9a72e16f5045e68cbd24 Reviewed-on: https://go-review.googlesource.com/c/go/+/720642 Auto-Submit: Alan Donovan <adonovan@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-11-12os/exec: include Cmd.Start in the list of methods that run CmdSean Liao
Fixes #76265 Change-Id: I451271c5662dd3bcdeec07b55761b15f64c00dcd Reviewed-on: https://go-review.googlesource.com/c/go/+/719860 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com>
2025-11-04os: ignore O_TRUNC errors on named pipes and terminal devices on Windowsqmuntal
Prior to Go 1.24, os.OpenFile used to support O_TRUNC on named pipes and terminal devices, even when the truncation was really ignored. This behavior was consistent with Unix semantics. CL 618836 changed the implementation of os.OpenFile on Windows and unintentionally started returning an error when O_TRUNC was used on such files. Fixes #76071 Change-Id: Id10d3d8120ae9aa0548ef05423a172ff4e502ff9 Reviewed-on: https://go-review.googlesource.com/c/go/+/716420 Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2025-10-29internal/itoa, internal/runtime/strconv: deleteRuss Cox
Replaced by internal/strconv. Change-Id: I0656a9ad5075e60339e963fbae7d194d2f3e16be Reviewed-on: https://go-review.googlesource.com/c/go/+/716001 Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-21os: support deleting read-only files in RemoveAll on older Windows versionsqmuntal
The Windows implementation of RemoveAll supports deleting read-only files only on file systems that supports POSIX semantics and on newer Windows versions (Windows 10 RS5 and latter). For all the other cases, the read-only bit was not clearer before deleting read-only files, so they fail to delete. Note that this case was supported prior to CL 75922, which landed on Go 1.25. Fixes #75922 Change-Id: Id6e6477f42e1952d08318ca3e4ab7c1648969f66 Reviewed-on: https://go-review.googlesource.com/c/go/+/713480 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Damien Neil <dneil@google.com>
2025-10-17all: remove unnecessary loop variable copies in testsTobias Klauser
Copying the loop variable is no longer necessary since Go 1.22. Change-Id: Iebb21dac44a20ec200567f1d786f105a4ee4999d Reviewed-on: https://go-review.googlesource.com/c/go/+/711640 Reviewed-by: Florian Lehner <lehner.florian86@gmail.com> Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-13all: replace calls to errors.As with errors.AsTypeJulien Cretel
This change replaces most occurrences (in code as well as in comments) of errors.As with errors.AsType. It leaves the errors package and vendored code untouched. Change-Id: I3bde73f318a0b408bdb8f5a251494af15a13118a GitHub-Last-Rev: 8aaaa36a5a12d2a6a90c6d51680464e1a3115139 GitHub-Pull-Request: golang/go#75698 Reviewed-on: https://go-review.googlesource.com/c/go/+/708495 Auto-Submit: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2025-09-26os/user: simplify go:buildKir Kolyshkin
The go:build constraint for these files is way too complicated, and can be simplified by using unix tag. Change-Id: Id8278db0ba799a4e951d3c976f77c7402bebb332 Reviewed-on: https://go-review.googlesource.com/c/go/+/703155 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Mark Freeman <markfreeman@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-09-26os/user: use getgrouplist on illumos && cgoKir Kolyshkin
The getgrouplist call is available on Illumos since December 2020: https://github.com/illumos/illumos-gate/commit/f2c438c5058c64b7373448f239156bf60009abcb We can assume it is available for users now. Let's switch to using it when cgo is enabled. Since neither LUCY nor legacy trybots provide illumos, I tested this locally in a OpenIndiana VM, with and without osusergo, with cgo enabled and disabled. This is a continuation of CL 315278. Fixes #14709 Change-Id: I922049e7ea5f450f6900914b30967e522e56cfc9 Reviewed-on: https://go-review.googlesource.com/c/go/+/702975 Reviewed-by: Andrew Stormont <andyjstormont@gmail.com> Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Kirill Kolyshkin <kolyshkin@gmail.com> TryBot-Bypass: Kirill Kolyshkin <kolyshkin@gmail.com>
2025-09-26internal/poll: don't call SetFilePointerEx in Seek for overlapped handlesqmuntal
Overlapped handles don't have the file pointer updated when performing I/O operations, so there is no need to call syscall.SetFilePointerEx in FD.Seek. Updating the in-memory offset is sufficient. Updates #74951 (provides a more complete fix) Change-Id: Ibede6625cdbd501fc92cfdf8ce2782ec291af2b6 Reviewed-on: https://go-review.googlesource.com/c/go/+/698035 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2025-09-16os/user: align test file name and build tagsKir Kolyshkin
TestNegativeUid tests code in cgo_lookup_unix.go, so let's use the very same go:build line for the test file, and rename the test file accordingly. Change-Id: Iee3dbc25aeb8a7659c734d97dde3e9c670e80fae Reviewed-on: https://go-review.googlesource.com/c/go/+/702976 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Mark Freeman <markfreeman@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-09-15all: replace strings.Split with strings.SplitSeq1911860538
In Go 1.25+, strings.SplitSeq offers better performance. Here are the benchmark results comparing strings.Split and strings.SplitSeq in a for-loop, with the benchmark code located in src/strings/iter_test.go: goos: darwin goarch: amd64 pkg: cmd/go/internal/auth cpu: Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz │ old.txt │ new.txt │ │ sec/op │ sec/op vs base │ ParseGitAuth/standard-8 281.4n ± 1% 218.0n ± 11% -22.54% (p=0.000 n=10) ParseGitAuth/with_url-8 549.1n ± 1% 480.5n ± 13% -12.48% (p=0.002 n=10) ParseGitAuth/minimal-8 235.4n ± 1% 197.3n ± 7% -16.20% (p=0.000 n=10) ParseGitAuth/complex-8 797.6n ± 2% 805.2n ± 4% ~ (p=0.481 n=10) ParseGitAuth/empty-8 87.48n ± 3% 63.25n ± 6% -27.71% (p=0.000 n=10) ParseGitAuth/malformed-8 228.8n ± 1% 171.2n ± 3% -25.17% (p=0.000 n=10) geomean 288.9n 237.7n -17.72% │ old.txt │ new.txt │ │ B/op │ B/op vs base │ ParseGitAuth/standard-8 192.00 ± 0% 96.00 ± 0% -50.00% (p=0.000 n=10) ParseGitAuth/with_url-8 400.0 ± 0% 288.0 ± 0% -28.00% (p=0.000 n=10) ParseGitAuth/minimal-8 144.00 ± 0% 80.00 ± 0% -44.44% (p=0.000 n=10) ParseGitAuth/complex-8 528.0 ± 0% 400.0 ± 0% -24.24% (p=0.000 n=10) ParseGitAuth/empty-8 32.00 ± 0% 16.00 ± 0% -50.00% (p=0.000 n=10) ParseGitAuth/malformed-8 176.00 ± 0% 80.00 ± 0% -54.55% (p=0.000 n=10) geomean 179.0 102.1 -42.96% │ old.txt │ new.txt │ │ allocs/op │ allocs/op vs base │ ParseGitAuth/standard-8 3.000 ± 0% 2.000 ± 0% -33.33% (p=0.000 n=10) ParseGitAuth/with_url-8 4.000 ± 0% 3.000 ± 0% -25.00% (p=0.000 n=10) ParseGitAuth/minimal-8 3.000 ± 0% 2.000 ± 0% -33.33% (p=0.000 n=10) ParseGitAuth/complex-8 4.000 ± 0% 3.000 ± 0% -25.00% (p=0.000 n=10) ParseGitAuth/empty-8 2.000 ± 0% 1.000 ± 0% -50.00% (p=0.000 n=10) ParseGitAuth/malformed-8 3.000 ± 0% 2.000 ± 0% -33.33% (p=0.000 n=10) geomean 3.086 2.040 -33.91% Updates #69315. Change-Id: Id0219edea45d9658d527b863162ebe917e7821d9 GitHub-Last-Rev: 392b315e122f2c9ef8703ca2dbce8f82ec198556 GitHub-Pull-Request: golang/go#75259 Reviewed-on: https://go-review.googlesource.com/c/go/+/701015 Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Emmanuel Odeke <emmanuel@orijtech.com>
2025-09-15os: add (*Process).WithHandleKir Kolyshkin
Implement (*Process).WithHandle, add tests for all platforms. Fixes #70352 Change-Id: I7a8012fb4e1e1b4ce1e75a59403ff6e77504fc56 Reviewed-on: https://go-review.googlesource.com/c/go/+/699615 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Mark Freeman <markfreeman@google.com> Auto-Submit: Kirill Kolyshkin <kolyshkin@gmail.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2025-09-15os: add and use errProcessReleasedKir Kolyshkin
This error is already used in three places, so let's define it. Change-Id: I73565d94aebcf3d5a278201d96839d82db85a2d4 Reviewed-on: https://go-review.googlesource.com/c/go/+/702436 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Mark Freeman <markfreeman@google.com> Reviewed-by: Sean Liao <sean@liao.dev> Reviewed-by: Michael Pratt <mpratt@google.com>
2025-09-15internal/syscall/unix: add KernelVersionGEKir Kolyshkin
There are a few places in the code which checks that the running kernel is greater than or equal to x.y. The check takes a few lines and the checking code is somewhat distracting. Let's abstract this check into a simple function, KernelVersionGE, and convert the users accordingly. Add a test case (I'm not sure it has much value, can be dropped). Change-Id: I8ec91dcc7452363361f95e46794701c0ae57d956 Reviewed-on: https://go-review.googlesource.com/c/go/+/700796 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Mark Freeman <markfreeman@google.com>
2025-09-06os: reject OpenDir of a non-directory file in Plan 9Richard Miller
Check that the path argument to OpenDir in Plan 9 is a directory, and return error syscall.ENOTDIR if it is not. Fixes #75196 Change-Id: I3bec6b6b40a38c21264b5d22ff3e7dfbf8c1c6d7 Reviewed-on: https://go-review.googlesource.com/c/go/+/700855 Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: David du Colombier <0intro@gmail.com>
2025-08-29os,syscall: pass file flags to CreateFile on Windowsqmuntal
Add support for FILE_FLAG_* constants in the flag argument of os.OpenFile and syscall.Open on Windows. Passing invalid flags will result in an error. Updates #73676 Change-Id: Ie215a3dd14f0d74141533f0a07865a02a67a3846 Reviewed-on: https://go-review.googlesource.com/c/go/+/699415 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-08-27os: return nil slice when ReadDir is used with a file on file_windowsqmuntal
ReadDir should return (nil, ENOTDIR) when the path points to a file instead of a directory. That's the behavior on Unix systems, and it also used to be the behavior on Windows. However, Windows currently returns ([]DirEntry{}, ENOTDIR). We should change the implementation to match the expected behavior. Fixed #75157 Change-Id: I3a3ddb71b5cd6e51dbca435a1585f01116844d4a Reviewed-on: https://go-review.googlesource.com/c/go/+/699375 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Steven Hartland <stevenmhartland@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-08-25os: set full name for Roots created with Root.OpenRootDamien Neil
Set the Name for a Root created within a Root to be the concatenation of the parent's path and the name used to open the child. This matches the behavior for files opened within a Root with Root.Open. Fixes #73868 Change-Id: Idf4021602ac25556721b7ef6924dec652c7bf4db Reviewed-on: https://go-review.googlesource.com/c/go/+/698376 Reviewed-by: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-08-22internal/syscall/windows: increase internal Windows O_ flags valuesqmuntal
The lowercase o_ flags are invented values. These conflict with constants that will soon be allowed by os.OpenFile, which values will be mandated by the Windows API. To avoid this overlap, the internal values have been increased to the 33-63 bit range, as the Windows ones are in the 0-32 bit range. Updates #73676 Change-Id: I0f657f3ed3403de150f1730a5a65ae887a18a4e9 Reviewed-on: https://go-review.googlesource.com/c/go/+/697363 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-08-22os: fix Root.MkdirAll to handle race of directory creationdatabase64128
No tests were added, because in order to reproduce, the directory would have to be created precisely between the rootOpenDir and mkdirat calls, which is impossible to do in a test. Fixes #75114 Change-Id: I6f86a5b33c87452c35728318eaf2169a7534ef37 Reviewed-on: https://go-review.googlesource.com/c/go/+/698215 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Sean Liao <sean@liao.dev> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Auto-Submit: Sean Liao <sean@liao.dev>
2025-08-20internal/poll: don't call Seek for overlapped Windows handlesqmuntal
Overlapped handles don't have the file pointer updated when performing I/O operations, so there is no need to call FD.Seek to reset the file pointer. Also, some overlapped file handles don't support seeking. See #74951. Fixes #74951. Change-Id: I0edd53beed7d3862730f3b2ed5fe9ba490e66c06 Reviewed-on: https://go-review.googlesource.com/c/go/+/697295 Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2025-08-20internal/poll: set the correct file offset in FD.Seek for Windows overlapped ↵qmuntal
handles Windows doesn't keep the file pointer for overlapped file handles. To work around this, we keep track of the current offset ourselves and use it on every Read/Write operation. When the user calls File.Seek with whence == io.SeekCurrent, it expects that the offset we keep track of is also accounted for, else the the seek'ed value won't match the file pointer seen by the user. Updates #74951. Fixes #75081. Change-Id: Ieca7c3779e5349292883ffc293a8474088a4dec7 Reviewed-on: https://go-review.googlesource.com/c/go/+/697275 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2025-08-19os: fix path in MkdirTemp error messageJonathan Conder
Fixes #75012 Change-Id: I9dd3ba8987bde9db93769a1b05d13b162ba5332d Reviewed-on: https://go-review.googlesource.com/c/go/+/696715 Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Sean Liao <sean@liao.dev> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Sean Liao <sean@liao.dev> Reviewed-by: David Chase <drchase@google.com>
2025-08-13os/exec: fix incorrect expansion of ".." in LookPath on plan9Richard Miller
The correction in CL 685755 is incomplete for plan9, where path search is performed even on file strings containing "/". By applying filepath.Clean to the argument of validateLookPath, we can check for bogus file strings containing ".." where the later call to filepath.Join would transform a path like "badfile/dir/.." to "badfile" even where "dir" isn't a directory or doesn't exist. For #74466 Fixes #74892 Change-Id: I3f8b73a1de6bc7d8001b1ca8e74b78722408548e Reviewed-on: https://go-review.googlesource.com/c/go/+/693935 Reviewed-by: David du Colombier <0intro@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2025-08-11net, os, file/filepath, syscall: use slices.Equal in testsTobias Klauser
Use slices.Equal to compare slices instead of strings.Join and then comparing strings. Change-Id: Ib916002b7357bd7f4e66b853dd7af8d98eba5549 Reviewed-on: https://go-review.googlesource.com/c/go/+/690475 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-07-29os/exec: fix incorrect expansion of "", "." and ".." in LookPathOlivier Mengué
Fix incorrect expansion of "" and "." when $PATH contains an executable file or, on Windows, a parent directory of a %PATH% element contains an file with the same name as the %PATH% element but with one of the %PATHEXT% extension (ex: C:\utils\bin is in PATH, and C:\utils\bin.exe exists). Fix incorrect expansion of ".." when $PATH contains an element which is an the concatenation of the path to an executable file (or on Windows a path that can be expanded to an executable by appending a %PATHEXT% extension), a path separator and a name. "", "." and ".." are now rejected early with ErrNotFound. Fixes CVE-2025-47906 Fixes #74466 Change-Id: Ie50cc0a660fce8fbdc952a7f2e05c36062dcb50e Reviewed-on: https://go-review.googlesource.com/c/go/+/685755 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Roland Shoemaker <roland@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
2025-07-28os/user: fix tests to pass on non-english WindowsOlivier Mengué
Tests on Windows are dependent on the english names of system accounts and groups. But on a french install of Windows the system accounts are: - AUTORITE NT\Système - AUTORITE NT\SERVICE LOCAL - AUTORITE NT\SERVICE RÉSEAU To allow the tests to pass on non-english Windows we only log differences in user/group names if GetSystemDefaultLCID() reports a non-english LCID, instead of failing. Change-Id: Ib81acc2896c45675fa3faf5dc390b57ec5159689 Reviewed-on: https://go-review.googlesource.com/c/go/+/688715 Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Mark Freeman <mark@golang.org> Reviewed-by: Quim Muntal <quimmuntal@gmail.com>
2025-07-25os/user: user random name for the test user accountqmuntal
TestImpersonated and TestGroupIdsTestUser are flaky due to sporadic failures when creating the test user account when running the tests from different processes at the same time. This flakiness can be fixed by using a random name for the test user account. Fixes #73523 Fixes #74727 Fixes #74728 Fixes #74729 Fixes #74745 Fixes #74751 Cq-Include-Trybots: luci.golang.try:gotip-windows-amd64-longtest Change-Id: Ib2283a888437420502b1c11d876c975f5af4bc03 Reviewed-on: https://go-review.googlesource.com/c/go/+/690175 Auto-Submit: Quim Muntal <quimmuntal@gmail.com> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Bypass: Dmitri Shuralyov <dmitshur@golang.org>
2025-07-18os: revert the use of AddCleanup to close files and rootsCarlos Amedee
This reverts commit fdaac84480b02e600660d0ca7c15339138807107. Updates #70907 Updates #74574 Updates #74642 Reason for revert: Issue #74574 Change-Id: I7b55b85736e4210d9b6f3fd7a24050ac7bdefef9 Reviewed-on: https://go-review.googlesource.com/c/go/+/688435 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-07-15os: remove useless error checkguoguangwu
Change-Id: Ifeb5fecc6e28b79ac03e7dc2ce9531fe5eed3097 GitHub-Last-Rev: 087cf95965920c96befad5adb9e481bdf913d50a GitHub-Pull-Request: golang/go#66260 Reviewed-on: https://go-review.googlesource.com/c/go/+/570895 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Sean Liao <sean@liao.dev> Auto-Submit: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Florian Lehner <lehner.florian86@gmail.com> Reviewed-by: Rob Pike <r@golang.org>