-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
nil pointer deference in proto.Size #631
Comments
To reproduce: package main
import (
"fmt"
"github.com/coreos/etcd/etcdserver/etcdserverpb"
"github.com/golang/protobuf/proto"
)
func main() {
var msg *etcdserverpb.PutResponse
m := proto.Message(msg)
a, b := m.(proto.Marshaler)
fmt.Println(a, b) // <nil> true
// trigger panic
a.Marshal()
/*
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7e2826]
goroutine 1 [running]:
github.com/coreos/etcd/etcdserver/etcdserverpb.(*PutResponse).Size(0x0, 0x9cbe00)
/home/gyuho/go/src/github.com/coreos/etcd/etcdserver/etcdserverpb/rpc.pb.go:8148 +0x26
github.com/coreos/etcd/etcdserver/etcdserverpb.(*PutResponse).Marshal(0x0, 0x2, 0x2, 0xb, 0x0, 0x0)
/home/gyuho/go/src/github.com/coreos/etcd/etcdserver/etcdserverpb/rpc.pb.go:5161 +0x2f
main.main()
/home/gyuho/p.go:15 +0xce
exit status 2
*/
} |
Turns out that the input to |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
When adding a
proto.Size()
call to code in etcd, we encountered this error:Here the nil pointer dereference appears to occur here:
https://github.com/coreos/etcd/blob/c6e18c712c7cc336a86404478297afa6063a72eb/etcdserver/etcdserverpb/rpc.pb.go#L8148
The nil was propagated here:
https://github.com/coreos/etcd/blob/c6e18c712c7cc336a86404478297afa6063a72eb/etcdserver/etcdserverpb/rpc.pb.go#L5161
And appears to have originated here:
protobuf/proto/table_marshal.go
Line 2602 in b4deda0
Suggesting that a nil check needs to be added to
f m, ok := pb.(Marshaler); ok {
?Versions:
github.com/golang/protobuf v1.1.0
github.com/gogo/protobuf v1.0.0
The text was updated successfully, but these errors were encountered: