[24.0 backport] windows: fix --register-service when executed from within binary directory #46215
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Go 1.15.7 contained a security fix for CVE-2021-3115, which allowed arbitrary code to be executed at build time when using cgo on Windows.
This issue was not limited to the go command itself, and could also affect binaries that use
os.Command
,os.LookPath
, etc.From the related blogpost (https://blog.golang.org/path-security):
At time of the go1.15 release, the Go team considered changing the behavior of
os.LookPath()
andexec.LookPath()
to be a breaking change, and made the behavior "opt-in" by providing thegolang.org/x/sys/execabs
package as a replacement.However, for the go1.19 release, this changed, and the default behavior of
os.LookPath()
andexec.LookPath()
was changed. From the release notes: https://go.dev/doc/go1.19#os-exec-pathA result of this change was that registering the daemon as a Windows service no longer worked when done from within the directory of the binary itself:
Note that using an absolute path would work around the issue:
This patch changes
registerService()
to useos.Executable()
, instead of depending onos.Args[0]
andexec.LookPath()
for resolving the absolute path of the binary.(cherry picked from commit 3e8fda0)
- What I did
- How I did it
- How to verify it
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)