diff --git a/go.mod b/go.mod index 22a7c92e..4495edfb 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ retract ( ) require ( - github.com/danieljoos/wincred v1.2.2 + github.com/danieljoos/wincred v1.2.3 github.com/keybase/go-keychain v0.0.1 ) diff --git a/go.sum b/go.sum index 25ec7fd9..24be54b1 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/danieljoos/wincred v1.2.2 h1:774zMFJrqaeYCK2W57BgAem/MLi6mtSE47MB6BOJ0i0= -github.com/danieljoos/wincred v1.2.2/go.mod h1:w7w4Utbrz8lqeMbDAK0lkNJUv5sAOkFi7nd/ogr0Uh8= +github.com/danieljoos/wincred v1.2.3 h1:v7dZC2x32Ut3nEfRH+vhoZGvN72+dQ/snVXo/vMFLdQ= +github.com/danieljoos/wincred v1.2.3/go.mod h1:6qqX0WNrS4RzPZ1tnroDzq9kY3fu1KwE7MRLQK4X0bs= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/keybase/go-keychain v0.0.1 h1:way+bWYa6lDppZoZcgMbYsvC7GxljxrskdNInRtuthU= @@ -8,8 +8,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= -github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= -github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/vendor/github.com/danieljoos/wincred/conversion.go b/vendor/github.com/danieljoos/wincred/conversion.go index bc04f50f..859aa040 100644 --- a/vendor/github.com/danieljoos/wincred/conversion.go +++ b/vendor/github.com/danieljoos/wincred/conversion.go @@ -31,13 +31,13 @@ func utf16FromString(str string) []uint16 { // goBytes copies the given C byte array to a Go byte array (see `C.GoBytes`). // This function avoids having cgo as dependency. -func goBytes(src uintptr, len uint32) []byte { - if src == uintptr(0) { +func goBytes(src *byte, len uint32) []byte { + if src == nil || len == 0 { return []byte{} } rv := make([]byte, len) copy(rv, *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{ - Data: src, + Data: uintptr(unsafe.Pointer(src)), Len: int(len), Cap: int(len), }))) @@ -59,7 +59,7 @@ func sysToCredential(cred *sysCREDENTIAL) (result *Credential) { result.CredentialBlob = goBytes(cred.CredentialBlob, cred.CredentialBlobSize) result.Attributes = make([]CredentialAttribute, cred.AttributeCount) attrSlice := *(*[]sysCREDENTIAL_ATTRIBUTE)(unsafe.Pointer(&reflect.SliceHeader{ - Data: cred.Attributes, + Data: uintptr(unsafe.Pointer(cred.Attributes)), Len: int(cred.AttributeCount), Cap: int(cred.AttributeCount), })) @@ -85,17 +85,13 @@ func sysFromCredential(cred *Credential) (result *sysCREDENTIAL) { result.LastWritten = syscall.NsecToFiletime(cred.LastWritten.UnixNano()) result.CredentialBlobSize = uint32(len(cred.CredentialBlob)) if len(cred.CredentialBlob) > 0 { - result.CredentialBlob = uintptr(unsafe.Pointer(&cred.CredentialBlob[0])) - } else { - result.CredentialBlob = 0 + result.CredentialBlob = &cred.CredentialBlob[0] } result.Persist = uint32(cred.Persist) result.AttributeCount = uint32(len(cred.Attributes)) attributes := make([]sysCREDENTIAL_ATTRIBUTE, len(cred.Attributes)) if len(attributes) > 0 { - result.Attributes = uintptr(unsafe.Pointer(&attributes[0])) - } else { - result.Attributes = 0 + result.Attributes = &attributes[0] } for i := range cred.Attributes { inAttr := &cred.Attributes[i] @@ -104,9 +100,7 @@ func sysFromCredential(cred *Credential) (result *sysCREDENTIAL) { outAttr.Flags = 0 outAttr.ValueSize = uint32(len(inAttr.Value)) if len(inAttr.Value) > 0 { - outAttr.Value = uintptr(unsafe.Pointer(&inAttr.Value[0])) - } else { - outAttr.Value = 0 + outAttr.Value = &inAttr.Value[0] } } result.TargetAlias, _ = syscall.UTF16PtrFromString(cred.TargetAlias) diff --git a/vendor/github.com/danieljoos/wincred/sys.go b/vendor/github.com/danieljoos/wincred/sys.go index fb8a6ac0..a499970d 100644 --- a/vendor/github.com/danieljoos/wincred/sys.go +++ b/vendor/github.com/danieljoos/wincred/sys.go @@ -5,6 +5,7 @@ package wincred import ( "reflect" + "runtime" "syscall" "unsafe" @@ -33,10 +34,10 @@ type sysCREDENTIAL struct { Comment *uint16 LastWritten windows.Filetime CredentialBlobSize uint32 - CredentialBlob uintptr + CredentialBlob *byte Persist uint32 AttributeCount uint32 - Attributes uintptr + Attributes *sysCREDENTIAL_ATTRIBUTE TargetAlias *uint16 UserName *uint16 } @@ -46,7 +47,7 @@ type sysCREDENTIAL_ATTRIBUTE struct { Keyword *uint16 Flags uint32 ValueSize uint32 - Value uintptr + Value *byte } // https://docs.microsoft.com/en-us/windows/desktop/api/wincred/ns-wincred-_credentialw @@ -93,6 +94,8 @@ func sysCredWrite(cred *Credential, typ sysCRED_TYPE) error { uintptr(unsafe.Pointer(ncred)), 0, ) + // Make sure everything reachable from ncred stays alive through the call. + runtime.KeepAlive(ncred) if ret == 0 { return err } diff --git a/vendor/modules.txt b/vendor/modules.txt index 0e9ca64d..67315ad1 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,4 +1,4 @@ -# github.com/danieljoos/wincred v1.2.2 +# github.com/danieljoos/wincred v1.2.3 ## explicit; go 1.18 github.com/danieljoos/wincred # github.com/keybase/go-keychain v0.0.1