google/go-tpm

Possible Issue with Reflection Helper

matt-tsai opened this issue · 1 comments

`$ go test -run TestCertify
{AttestationData:{Magic:4283712327 Type:32791 QualifiedSigner:{Buffer:[0 11 9 250 56 153 231 56 169 65 0 237 74 163 159 97 153 233 30 248 73 20 49 76 187 226 127 52 200 18 251 18 1 140]} ExtraData:{Buffer:[]} ClockInfo:{Clock:64 ResetCount:2224517829 RestartCount:2044159783 Safe:true} FirmwareVersion:8519710996764275452 Attested:{NV: CommandAudit: SessionAudit: Certify:0xc00025a120 Quote: Time: Creation: NVDigest:}}}--- FAIL: TestCertify (0.07s)
panic: reflect.Value.Interface: cannot return value obtained from unexported field or method [recovered]
panic: reflect.Value.Interface: cannot return value obtained from unexported field or method

goroutine 19 [running]:
testing.tRunner.func1.2({0x6f1740, 0x7beaf0})
/usr/lib/google-golang/src/testing/testing.go:1396 +0x24e
testing.tRunner.func1()
/usr/lib/google-golang/src/testing/testing.go:1399 +0x39f
panic({0x6f1740, 0x7beaf0})
/usr/lib/google-golang/src/runtime/panic.go:884 +0x212
reflect.valueInterface({0x6f0f40?, 0xc00025a8e8?, 0x5?}, 0xe0?)
/usr/lib/google-golang/src/reflect/value.go:1504 +0xd8
reflect.Value.Interface(...)
/usr/lib/google-golang/src/reflect/value.go:1493
github.com/google/go-tpm/direct/tpm2.marshalNumeric(0x1?, {0x6f0f40?, 0xc00025a8e8?, 0xc0001db068?})
/usr/local/google/home/matthewtsai/git/go-tpm/direct/tpm2/reflect.go:189 +0x36
github.com/google/go-tpm/direct/tpm2.marshal(0x71f5a0?, {0x6f0f40?, 0xc00025a8e8?, 0x8?})
/usr/local/google/home/matthewtsai/git/go-tpm/direct/tpm2/reflect.go:144 +0x269
github.com/google/go-tpm/direct/tpm2.marshalStruct(0x73cc40?, {0x71f5a0?, 0xc00025a8d0?, 0xc00025a900?})
/usr/local/google/home/matthewtsai/git/go-tpm/direct/tpm2/reflect.go:305 +0x1b9b
github.com/google/go-tpm/direct/tpm2.marshal(0x745880?, {0x73cc40?, 0xc00025a8d0?, 0x4f1aca?})
/usr/local/google/home/matthewtsai/git/go-tpm/direct/tpm2/reflect.go:150 +0x375
github.com/google/go-tpm/direct/tpm2.Marshal({0xc0001dbbd8?, 0x2?, 0x746031?})
/usr/local/google/home/matthewtsai/git/go-tpm/direct/tpm2/reflect.go:132 +0xff
github.com/google/go-tpm/direct/tpm2.TestCertify(0xc000083040)
/usr/local/google/home/matthewtsai/git/go-tpm/direct/tpm2/certify_test.go:138 +0xb76
testing.tRunner(0xc000083040, 0x771940)
/usr/lib/google-golang/src/testing/testing.go:1446 +0x10b
created by testing.(*T).Run
/usr/lib/google-golang/src/testing/testing.go:1493 +0x35f
exit status 2
FAIL github.com/google/go-tpm/direct/tpm2 0.098s`
https://github.com/matt-tsai/go-tpm/blob/certify/direct/tpm2/certify_test.go

This was my mistake. I pointed @matt-tsai at Marshal thinking it took in a bytes.Buffer like marshal does. But it returns []byte, error.

I filed #292 to track improving the ergonomics here - ideally, Marshal wouldn't let you pass in something that will panic.