]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/asn1: unmarshal bool values correctly dealing with the ANY type
authorJes Cok <xigua67damn@gmail.com>
Sat, 29 Jun 2024 18:46:12 +0000 (02:46 +0800)
committerGopher Robot <gobot@golang.org>
Mon, 23 Sep 2024 18:05:24 +0000 (18:05 +0000)
Fixes #68241

Change-Id: I1ee81aa50c2f39f535ad27309e855f19acb2f2ea
Reviewed-on: https://go-review.googlesource.com/c/go/+/595796
Auto-Submit: Roland Shoemaker <roland@golang.org>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
src/encoding/asn1/asn1.go
src/encoding/asn1/marshal_test.go

index 781ab8769164b0cdf02841af3447c7591c4daa73..56e007d3a653436b2b0b0fb391c27e654e3b50cf 100644 (file)
@@ -702,6 +702,8 @@ func parseField(v reflect.Value, bytes []byte, initOffset int, params fieldParam
                if !t.isCompound && t.class == ClassUniversal {
                        innerBytes := bytes[offset : offset+t.length]
                        switch t.tag {
+                       case TagBoolean:
+                               result, err = parseBool(innerBytes)
                        case TagPrintableString:
                                result, err = parsePrintableString(innerBytes)
                        case TagNumericString:
index 64ce47640034bed9d94cb2ab9ac0d762232f4aac..dfd6d4e40b9868cca2b3ccb4bd1d2228ef01ce01 100644 (file)
@@ -311,6 +311,26 @@ func TestIssue11130(t *testing.T) {
        }
 }
 
+func TestIssue68241(t *testing.T) {
+       for i, want := range []any{false, true} {
+               data, err := Marshal(want)
+               if err != nil {
+                       t.Errorf("cannot Marshal: %v", err)
+                       return
+               }
+
+               var got any
+               _, err = Unmarshal(data, &got)
+               if err != nil {
+                       t.Errorf("cannot Unmarshal: %v", err)
+                       return
+               }
+               if !reflect.DeepEqual(got, want) {
+                       t.Errorf("#%d Unmarshal, got: %v, want: %v", i, got, want)
+               }
+       }
+}
+
 func BenchmarkMarshal(b *testing.B) {
        b.ReportAllocs()