Skip to content

Commit 77ef9c7

Browse files
bradfitzadg
authored andcommitted
syscall: point to x/sys in DLL loading docs, update syscall generator
Updates the syscall generator for patchset 4 of https://golang.org/cl/21388. Updates #14959 Change-Id: Icbd6df489887d3dcc076dfc73d4feb1376abaf8b Reviewed-on: https://go-review.googlesource.com/21428 Reviewed-by: Alex Brainman <[email protected]> Reviewed-on: https://go-review.googlesource.com/21680 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent a241a38 commit 77ef9c7

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/syscall/dll_windows.go

+13
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ type DLL struct {
3737
}
3838

3939
// LoadDLL loads the named DLL file into memory.
40+
//
41+
// If name is not an absolute path and is not a known system DLL used by
42+
// Go, Windows will search for the named DLL in many locations, causing
43+
// potential DLL preloading attacks.
44+
//
45+
// Use LazyDLL in golang.org/x/sys/windows for a secure way to
46+
// load system DLLs.
4047
func LoadDLL(name string) (*DLL, error) {
4148
namep, err := UTF16PtrFromString(name)
4249
if err != nil {
@@ -174,6 +181,12 @@ func (p *Proc) Call(a ...uintptr) (r1, r2 uintptr, lastErr error) {
174181
// It will delay the load of the DLL until the first
175182
// call to its Handle method or to one of its
176183
// LazyProc's Addr method.
184+
//
185+
// LazyDLL is subject to the same DLL preloading attacks as documented
186+
// on LoadDLL.
187+
//
188+
// Use LazyDLL in golang.org/x/sys/windows for a secure way to
189+
// load system DLLs.
177190
type LazyDLL struct {
178191
mu sync.Mutex
179192
dll *DLL // non nil once DLL is loaded

src/syscall/mksyscall_windows.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -707,9 +707,9 @@ func (src *Source) Generate(w io.Writer) error {
707707
}
708708
if *sysRepo {
709709
if packageName == "windows" {
710-
return "&LazyDLL{Name: " + arg + ", Flags: LoadLibrarySearchSystem32}"
710+
return "&LazyDLL{Name: " + arg + ", System: true}"
711711
} else {
712-
return "&windows.LazyDLL{Name: " + arg + ", Flags: windows.LoadLibrarySearchSystem32}"
712+
return "&windows.LazyDLL{Name: " + arg + ", System: true}"
713713
}
714714
} else {
715715
return syscalldot() + "NewLazyDLL(" + arg + ")"

0 commit comments

Comments
 (0)