diff --git a/.appveyor.yml b/.appveyor.yml new file mode 100644 index 0000000..c0e1ae0 --- /dev/null +++ b/.appveyor.yml @@ -0,0 +1,40 @@ +skip_branch_with_pr: true +os: 'Visual Studio 2015' + +build: off + +environment: + matrix: + - ARCH: x64 + MSYS2_ARCH: x86_64 + MSYS2_DIR: msys64 + MSYSTEM: MINGW64 + GOPATH: c:\gopath + GOROOT: c:\go + GOARCH: amd64 + EXTLD: x86_64-w64-mingw32-gcc + - ARCH: x86 + MSYS2_ARCH: i686 + MSYS2_DIR: msys64 + MSYSTEM: MINGW32 + GOPATH: c:\gopath + GOROOT: c:\go + GOARCH: 386 + EXTLD: i686-w64-mingw32-gcc + +clone_folder: C:\gopath\src\github.com\mastahyeti\certstore + +before_test: + # Ensure CGO is enabled + - set CGO_ENABLED=1 + # Go paths + - set PATH=%GOROOT%\bin;C:\%GOPATH%\bin;%PATH% + # MSYS paths + - set PATH=C:\%MSYS2_DIR%\%MSYSTEM%\bin;C:\%MSYS2_DIR%\usr\bin;%PATH% + # Install build deps + - bash -lc "for n in `seq 1 3`; do pacman --noconfirm -S mingw-w64-%MSYS2_ARCH%-libtool && break || sleep 15; done" + # Install Go deps + - go get -t -v ./... + +test_script: + - go test -v ./... diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 11b0ef8..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,13 +0,0 @@ -version: "{build}" -clone_folder: c:\gopath\src\github.com\mastahyeti\certstore -environment: - GOPATH: c:\gopath - -install: - - set PATH=%PATH%;C:\msys64\mingw64\bin - - go version - - go get -t -v ./... -build_script: - - go build -test_script: - - go test -v diff --git a/certstore_windows.go b/certstore_windows.go index aa8a628..8c09e97 100644 --- a/certstore_windows.go +++ b/certstore_windows.go @@ -112,18 +112,18 @@ func (s *winStore) Identities() ([]Identity, error) { goto fail } - // maximum chain length. this is arbitrary - const maxChain = 1 << 30 + // not sure why this isn't 1 << 29 + const maxPointerArray = 1 << 28 // rgpChain is actually an array, but we only care about the first one. simpleChain := *chainCtx.rgpChain - if simpleChain.cElement < 1 || simpleChain.cElement > maxChain { + if simpleChain.cElement < 1 || simpleChain.cElement > maxPointerArray { err = errors.New("bad chain") goto fail } // Hacky way to get chain elements (c array) as a slice. - chainElts := (*[maxChain]C.PCERT_CHAIN_ELEMENT)(unsafe.Pointer(simpleChain.rgpElement))[:simpleChain.cElement:simpleChain.cElement] + chainElts := (*[maxPointerArray]C.PCERT_CHAIN_ELEMENT)(unsafe.Pointer(simpleChain.rgpElement))[:simpleChain.cElement:simpleChain.cElement] // Build chain of certificates from each elt's certificate context. chain := make([]C.PCCERT_CONTEXT, len(chainElts)) @@ -654,10 +654,17 @@ func (ss securityStatus) Error() string { } func stringToUTF16(s string) C.LPCWSTR { + // Not sure why this isn't 1 << 30... + const maxUint16Array = 1 << 29 + + if len(s) > maxUint16Array { + panic("string too long") + } + wstr := utf16.Encode([]rune(s)) p := C.calloc(C.size_t(len(wstr)+1), C.size_t(unsafe.Sizeof(uint16(0)))) - pp := (*[1 << 30]uint16)(p) + pp := (*[maxUint16Array]uint16)(p) copy(pp[:], wstr) return (C.LPCWSTR)(p)