@@ -112,18 +112,18 @@ func (s *winStore) Identities() ([]Identity, error) {
112112 goto fail
113113 }
114114
115- // maximum chain length. this is arbitrary
116- const maxChain = 1 << 30
115+ // not sure why this isn't 1 << 29
116+ const maxPointerArray = 1 << 28
117117
118118 // rgpChain is actually an array, but we only care about the first one.
119119 simpleChain := * chainCtx .rgpChain
120- if simpleChain .cElement < 1 || simpleChain .cElement > maxChain {
120+ if simpleChain .cElement < 1 || simpleChain .cElement > maxPointerArray {
121121 err = errors .New ("bad chain" )
122122 goto fail
123123 }
124124
125125 // Hacky way to get chain elements (c array) as a slice.
126- chainElts := (* [maxChain ]C.PCERT_CHAIN_ELEMENT )(unsafe .Pointer (simpleChain .rgpElement ))[:simpleChain .cElement :simpleChain .cElement ]
126+ chainElts := (* [maxPointerArray ]C.PCERT_CHAIN_ELEMENT )(unsafe .Pointer (simpleChain .rgpElement ))[:simpleChain .cElement :simpleChain .cElement ]
127127
128128 // Build chain of certificates from each elt's certificate context.
129129 chain := make ([]C.PCCERT_CONTEXT , len (chainElts ))
@@ -654,10 +654,17 @@ func (ss securityStatus) Error() string {
654654}
655655
656656func stringToUTF16 (s string ) C.LPCWSTR {
657+ // Not sure why this isn't 1 << 30...
658+ const maxUint16Array = 1 << 29
659+
660+ if len (s ) > maxUint16Array {
661+ panic ("string too long" )
662+ }
663+
657664 wstr := utf16 .Encode ([]rune (s ))
658665
659666 p := C .calloc (C .size_t (len (wstr )+ 1 ), C .size_t (unsafe .Sizeof (uint16 (0 ))))
660- pp := (* [1 << 30 ]uint16 )(p )
667+ pp := (* [maxUint16Array ]uint16 )(p )
661668 copy (pp [:], wstr )
662669
663670 return (C .LPCWSTR )(p )
0 commit comments