diff options
author | Adam Langley <agl@golang.org> | 2010-01-11 18:53:58 -0800 |
---|---|---|
committer | Adam Langley <agl@golang.org> | 2010-01-11 18:53:58 -0800 |
commit | aa26195a61879773d2335f64d9e818236dc5cc9f (patch) | |
tree | fc5b2f6317de77d0a68b237d98b26bf06cb95244 /src/pkg/asn1 | |
parent | 0d3572a8e95be8d65b03268cbcbcefe536dfa97f (diff) | |
download | golang-aa26195a61879773d2335f64d9e818236dc5cc9f.tar.gz |
asn1: fix parsing of elements after a string in a structure.
Fixes issue 516.
R=rsc
CC=golang-dev, golang-dev
http://codereview.appspot.com/184080
Diffstat (limited to 'src/pkg/asn1')
-rw-r--r-- | src/pkg/asn1/asn1.go | 11 | ||||
-rw-r--r-- | src/pkg/asn1/asn1_test.go | 6 |
2 files changed, 8 insertions, 9 deletions
diff --git a/src/pkg/asn1/asn1.go b/src/pkg/asn1/asn1.go index a422f28ad..430b035f5 100644 --- a/src/pkg/asn1/asn1.go +++ b/src/pkg/asn1/asn1.go @@ -609,6 +609,7 @@ func parseField(v reflect.Value, bytes []byte, initOffset int, params fieldParam return } innerBytes := bytes[offset : offset+t.length] + offset += t.length // We deal with the structures defined in this package first. switch fieldType { @@ -619,13 +620,11 @@ func parseField(v reflect.Value, bytes []byte, initOffset int, params fieldParam if err1 == nil { reflect.ArrayCopy(sliceValue, reflect.NewValue(newSlice).(reflect.ArrayOrSliceValue)) } - offset += t.length err = err1 return case bitStringType: structValue := v.(*reflect.StructValue) bs, err1 := parseBitString(innerBytes) - offset += t.length if err1 == nil { structValue.Set(reflect.NewValue(bs).(*reflect.StructValue)) } @@ -634,7 +633,6 @@ func parseField(v reflect.Value, bytes []byte, initOffset int, params fieldParam case timeType: ptrValue := v.(*reflect.PtrValue) time, err1 := parseUTCTime(innerBytes) - offset += t.length if err1 == nil { ptrValue.Set(reflect.NewValue(time).(*reflect.PtrValue)) } @@ -644,7 +642,6 @@ func parseField(v reflect.Value, bytes []byte, initOffset int, params fieldParam switch val := v.(type) { case *reflect.BoolValue: parsedBool, err1 := parseBool(innerBytes) - offset += t.length if err1 == nil { val.Set(parsedBool) } @@ -652,7 +649,6 @@ func parseField(v reflect.Value, bytes []byte, initOffset int, params fieldParam return case *reflect.IntValue: parsedInt, err1 := parseInt(innerBytes) - offset += t.length if err1 == nil { val.Set(parsedInt) } @@ -660,7 +656,6 @@ func parseField(v reflect.Value, bytes []byte, initOffset int, params fieldParam return case *reflect.Int64Value: parsedInt, err1 := parseInt64(innerBytes) - offset += t.length if err1 == nil { val.Set(parsedInt) } @@ -671,7 +666,7 @@ func parseField(v reflect.Value, bytes []byte, initOffset int, params fieldParam if structType.NumField() > 0 && structType.Field(0).Type == rawContentsType { - bytes := bytes[initOffset : offset+t.length] + bytes := bytes[initOffset:offset] val.Field(0).SetValue(reflect.NewValue(RawContent(bytes))) } @@ -686,7 +681,6 @@ func parseField(v reflect.Value, bytes []byte, initOffset int, params fieldParam return } } - offset += t.length // We allow extra bytes at the end of the SEQUENCE because // adding elements to the end has been used in X.509 as the // version numbers have increased. @@ -699,7 +693,6 @@ func parseField(v reflect.Value, bytes []byte, initOffset int, params fieldParam return } newSlice, err1 := parseSequenceOf(innerBytes, sliceType, sliceType.Elem()) - offset += t.length if err1 == nil { val.Set(newSlice) } diff --git a/src/pkg/asn1/asn1_test.go b/src/pkg/asn1/asn1_test.go index 5071facfc..43c746895 100644 --- a/src/pkg/asn1/asn1_test.go +++ b/src/pkg/asn1/asn1_test.go @@ -263,6 +263,11 @@ type TestContextSpecificTags2 struct { B int } +type TestElementsAfterString struct { + S string + A, B int +} + var unmarshalTestData []unmarshalTest = []unmarshalTest{ unmarshalTest{[]byte{0x02, 0x01, 0x42}, newInt(0x42)}, unmarshalTest{[]byte{0x30, 0x08, 0x06, 0x06, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d}, &TestObjectIdentifierStruct{[]int{1, 2, 840, 113549}}}, @@ -277,6 +282,7 @@ var unmarshalTestData []unmarshalTest = []unmarshalTest{ unmarshalTest{[]byte{0x30, 0x08, 0xa1, 0x03, 0x02, 0x01, 0x01, 0x02, 0x01, 0x02}, &TestContextSpecificTags2{1, 2}}, unmarshalTest{[]byte{0x01, 0x01, 0x00}, newBool(false)}, unmarshalTest{[]byte{0x01, 0x01, 0x01}, newBool(true)}, + unmarshalTest{[]byte{0x30, 0x0b, 0x13, 0x03, 0x66, 0x6f, 0x6f, 0x02, 0x01, 0x22, 0x02, 0x01, 0x33}, &TestElementsAfterString{"foo", 0x22, 0x33}}, } func TestUnmarshal(t *testing.T) { |