From a7f19e9c2041d17119bde681964de7f560cf41c0 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Mon, 16 Dec 2024 13:14:32 +0100 Subject: [PATCH 1/3] unix: add Dup3 on dragonfly Use the same implementation as on freebsd which is also what the dragonfly libc uses. Change-Id: I0ed513ae15fcb6dac77b2fc76f662723d66b75c6 Reviewed-on: https://go-review.googlesource.com/c/sys/+/636435 Auto-Submit: Tobias Klauser Reviewed-by: Ian Lance Taylor Reviewed-by: Carlos Amedee LUCI-TryBot-Result: Go LUCI Run-TryBot: Tobias Klauser TryBot-Result: Gopher Robot --- unix/dup3_test.go | 4 ++-- unix/syscall_dragonfly.go | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/unix/dup3_test.go b/unix/dup3_test.go index 9201e35580..12baf12625 100644 --- a/unix/dup3_test.go +++ b/unix/dup3_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build freebsd || linux || netbsd || openbsd +//go:build dragonfly || freebsd || linux || netbsd || openbsd package unix_test @@ -16,7 +16,7 @@ import ( ) func TestDup3(t *testing.T) { - tempFile, err := os.Create(filepath.Join(t.TempDir(), "TestDup")) + tempFile, err := os.Create(filepath.Join(t.TempDir(), "TestDup3")) if err != nil { t.Fatal(err) } diff --git a/unix/syscall_dragonfly.go b/unix/syscall_dragonfly.go index 97cb916f2c..be8c002070 100644 --- a/unix/syscall_dragonfly.go +++ b/unix/syscall_dragonfly.go @@ -246,6 +246,18 @@ func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err e return sendfile(outfd, infd, offset, count) } +func Dup3(oldfd, newfd, flags int) error { + if oldfd == newfd || flags&^O_CLOEXEC != 0 { + return EINVAL + } + how := F_DUP2FD + if flags&O_CLOEXEC != 0 { + how = F_DUP2FD_CLOEXEC + } + _, err := fcntl(oldfd, how, newfd) + return err +} + /* * Exposed directly */ From 680bd24a5f379f8bd7b015f25e94865905dd8b34 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 24 Dec 2024 20:44:46 +0000 Subject: [PATCH 2/3] windows: remove unused errString type It's no longer used since CL 165759. Change-Id: Ie8c834a6dd1147889ec47bf92a5d4cce08bbf4fd GitHub-Last-Rev: 3f0c460db144b70b008a762f12a6e0c1ff6bdfbf GitHub-Pull-Request: golang/sys#241 Reviewed-on: https://go-review.googlesource.com/c/sys/+/638716 Reviewed-by: Ian Lance Taylor Auto-Submit: Jorropo LUCI-TryBot-Result: Go LUCI Reviewed-by: Cherry Mui Reviewed-by: Jorropo Auto-Submit: Ian Lance Taylor --- windows/dll_windows.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/windows/dll_windows.go b/windows/dll_windows.go index 4e613cf633..04eb457716 100644 --- a/windows/dll_windows.go +++ b/windows/dll_windows.go @@ -410,7 +410,3 @@ func loadLibraryEx(name string, system bool) (*DLL, error) { } return &DLL{Name: name, Handle: h}, nil } - -type errString string - -func (s errString) Error() string { return string(s) } From d4ac05dc8c4c953ec29cae3df56c0833f4010763 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 24 Dec 2024 20:44:42 +0000 Subject: [PATCH 3/3] windows: update NewLazyDLL, LoadDLL docs to point to NewLazySystemDLL Point users to the NewLazySystemDLL utility that was added in CL 21592. Change-Id: I5fddd927fe6628f06a6266b225949c4227fb79f1 GitHub-Last-Rev: 1fe36ed335f040797ae2c778188e40c29604f135 GitHub-Pull-Request: golang/sys#240 Reviewed-on: https://go-review.googlesource.com/c/sys/+/638715 Reviewed-by: Jorropo Auto-Submit: Ian Lance Taylor Auto-Submit: Jorropo LUCI-TryBot-Result: Go LUCI Reviewed-by: Cherry Mui Reviewed-by: Ian Lance Taylor --- windows/dll_windows.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/windows/dll_windows.go b/windows/dll_windows.go index 04eb457716..3ca814f54d 100644 --- a/windows/dll_windows.go +++ b/windows/dll_windows.go @@ -43,8 +43,8 @@ type DLL struct { // LoadDLL loads DLL file into memory. // // Warning: using LoadDLL without an absolute path name is subject to -// DLL preloading attacks. To safely load a system DLL, use LazyDLL -// with System set to true, or use LoadLibraryEx directly. +// DLL preloading attacks. To safely load a system DLL, use [NewLazySystemDLL], +// or use [LoadLibraryEx] directly. func LoadDLL(name string) (dll *DLL, err error) { namep, err := UTF16PtrFromString(name) if err != nil { @@ -271,6 +271,9 @@ func (d *LazyDLL) NewProc(name string) *LazyProc { } // NewLazyDLL creates new LazyDLL associated with DLL file. +// +// Warning: using NewLazyDLL without an absolute path name is subject to +// DLL preloading attacks. To safely load a system DLL, use [NewLazySystemDLL]. func NewLazyDLL(name string) *LazyDLL { return &LazyDLL{Name: name} }