Add back LoadLibraryA fallback

This commit is contained in:
Vorapol Rinsatitnon
2024-09-27 04:05:44 +10:00
parent 1d132f7ae5
commit 4945989aba
7 changed files with 136 additions and 7 deletions

View File

@@ -1166,7 +1166,10 @@ uintptr_t cfunc(void) {
dll, err = syscall.LoadDLL(name)
if err == nil {
dll.Release()
t.Fatalf("Bad: insecure load of DLL by base name %q before sysdll registration: %v", name, err)
if wantLoadLibraryEx() {
t.Fatalf("Bad: insecure load of DLL by base name %q before sysdll registration: %v", name, err)
}
t.Skip("insecure load of DLL, but expected")
}
}
@@ -1212,6 +1215,24 @@ func TestBigStackCallbackSyscall(t *testing.T) {
}
}
// wantLoadLibraryEx reports whether we expect LoadLibraryEx to work for tests.
func wantLoadLibraryEx() bool {
return testenv.Builder() != "" && (runtime.GOARCH == "amd64" || runtime.GOARCH == "386")
}
func TestLoadLibraryEx(t *testing.T) {
use, have, flags := runtime.LoadLibraryExStatus()
if use {
return // success.
}
if wantLoadLibraryEx() {
t.Fatalf("Expected LoadLibraryEx+flags to be available. (LoadLibraryEx=%v; flags=%v)",
have, flags)
}
t.Skipf("LoadLibraryEx not usable, but not expected. (LoadLibraryEx=%v; flags=%v)",
have, flags)
}
var (
modwinmm = syscall.NewLazyDLL("winmm.dll")
modkernel32 = syscall.NewLazyDLL("kernel32.dll")