Commit fac10396 authored by Michal Bohuslávek's avatar Michal Bohuslávek Committed by Adam Langley

encoding/asn1: fix panic when Marshaling nil.

Fixes #11127.

Change-Id: Ibcfc3a05e91fa4260d70b04bee2bbba2376bd313
Reviewed-on: https://go-review.googlesource.com/13923Reviewed-by: default avatarAdam Langley <agl@golang.org>
parent 805e56ef
......@@ -940,3 +940,15 @@ func TestUnmarshalInvalidUTF8(t *testing.T) {
t.Fatalf("Expected error to mention %q but error was %q", expectedSubstring, err.Error())
}
}
func TestMarshalNilValue(t *testing.T) {
nilValueTestData := []interface{}{
nil,
struct{ v interface{} }{},
}
for i, test := range nilValueTestData {
if _, err := Marshal(test); err == nil {
t.Fatal("#%d: successfully marshaled nil value", i)
}
}
}
......@@ -506,6 +506,9 @@ func marshalBody(out *forkableWriter, value reflect.Value, params fieldParameter
}
func marshalField(out *forkableWriter, v reflect.Value, params fieldParameters) (err error) {
if !v.IsValid() {
return fmt.Errorf("asn1: cannot marshal nil value")
}
// If the field is an interface{} then recurse into it.
if v.Kind() == reflect.Interface && v.Type().NumMethod() == 0 {
return marshalField(out, v.Elem(), params)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment