Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/asn1: unexported field causes panic #17462

Closed
hirochachacha opened this issue Oct 16, 2016 · 6 comments
Closed

encoding/asn1: unexported field causes panic #17462

hirochachacha opened this issue Oct 16, 2016 · 6 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@hirochachacha
Copy link
Contributor

Please answer these questions before submitting your issue. Thanks!

What did you do?

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

package main

import (
    "encoding/asn1"
    "time"
)

type A struct {
    t time.Time
}

func main() {
    asn1.Marshal(A{})
}

What did you expect to see?

no panic.

What did you see instead?

panic: reflect.Value.Interface: cannot return value obtained from unexported field or method

goroutine 1 [running]:
panic(0xb14a0, 0xc420072080)
/Users/hiro/go/src/runtime/panic.go:527 +0x1a0
reflect.valueInterface(0xcdd20, 0xc42008a0e0, 0xb9, 0x133001, 0xcdd20, 0x1)
/Users/hiro/go/src/reflect/value.go:918 +0x1b5
reflect.Value.Interface(0xcdd20, 0xc42008a0e0, 0xb9, 0x130100, 0xcdd20)
/Users/hiro/go/src/reflect/value.go:907 +0x44
encoding/asn1.makeField(0xcdd20, 0xc42008a0e0, 0xb9, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
/Users/hiro/go/src/encoding/asn1/marshal.go:582 +0x9c6
encoding/asn1.makeBody(0xbb180, 0xc42008a0e0, 0x99, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc42003bbe0, ...)
/Users/hiro/go/src/encoding/asn1/marshal.go:453 +0xa95
encoding/asn1.makeField(0xbb180, 0xc42008a0e0, 0x99, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc42008a0e0, ...)
/Users/hiro/go/src/encoding/asn1/marshal.go:596 +0x2b4
encoding/asn1.Marshal(0xbb180, 0xc42008a0e0, 0xbb180, 0xc42008a0e0, 0x0, 0x0, 0x0)
/Users/hiro/go/src/encoding/asn1/marshal.go:641 +0xe6
main.main()
/Users/hiro/a.go:13 +0x69
exit status 2

Does this issue reproduce with the latest release (go1.7.1)?

System details

go version devel +05cbf45 Sun Oct 16 13:47:13 2016 +0900 darwin/amd64
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/hiro/.go"
GORACE=""
GOROOT="/Users/hiro/go"
GOTOOLDIR="/Users/hiro/go/pkg/tool/darwin_amd64"
TERM="dumb"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/wq/dwn8hs0x7njbzty9f68y61700000gn/T/go-build126282944=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
uname -v: Darwin Kernel Version 15.6.0: Mon Aug 29 20:21:34 PDT 2016; root:xnu-3248.60.11~1/RELEASE_X86_64
ProductName:    Mac OS X
ProductVersion: 10.11.6
BuildVersion:   15G1004
lldb --version: lldb-360.1.50
gdb --version: GNU gdb (GDB) 7.11.1
@odeke-em
Copy link
Member

Interestingly if you make the argument to Marshal a pointer ie &A{} instead of A{}, it doesn't panic and returns an error https://play.golang.org/p/f55UZE6hl6

@hirochachacha
Copy link
Contributor Author

ah, that's true.

@gopherbot
Copy link

CL https://golang.org/cl/31122 mentions this issue.

@quentinmit quentinmit added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 17, 2016
@quentinmit quentinmit added this to the Go1.8Maybe milestone Oct 17, 2016
@rsc
Copy link
Contributor

rsc commented Oct 20, 2016

This has panicked from day 1. I don't think we should start accepting structs with unexported fields. We could return an error instead though.

@hirochachacha
Copy link
Contributor Author

SGTM. I'll send another one.

@gopherbot
Copy link

CL https://golang.org/cl/31540 mentions this issue.

@golang golang locked and limited conversation to collaborators Nov 3, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants