Skip to content

encoding/asn1: bool values not unmarshaled into interface type #68241

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

Closed
bjangelo opened this issue Jun 28, 2024 · 4 comments
Closed

encoding/asn1: bool values not unmarshaled into interface type #68241

bjangelo opened this issue Jun 28, 2024 · 4 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@bjangelo
Copy link

Go version

go version go1.22.3 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/bangelo/.cache/go-build'
GOENV='/home/bangelo/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/bangelo/code/go/pkg/mod'
GOOS='linux'
GOPATH='/home/bangelo/code/go'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.3'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -fmessage-length=0 -ffile-prefix-map=/tmp/go-build324096014=/tmp/go-build -gno-record-gcc-switches'

What did you do?

Attempted to unmarshal boolean asn1 value into any type.

https://go.dev/play/p/QEFu_kJD6b4

package main

import (
	"encoding/asn1"
	"fmt"
	"log"
)

func main() {
	data, err := asn1.Marshal(true)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%v\n", data)

	var value any
	rest, err := asn1.Unmarshal(data, &value)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%d\n", len(rest))
	fmt.Printf("%T\n", value)
}

What did you see happen?

Unmarshal consumed the boolean TLV but did not populate the any type variable.

[1 1 255]
0
<nil>

What did you expect to see?

Unmarshal populate the any type variable.

[1 1 255]
0
bool
@bjangelo
Copy link
Author

Perhaps the parseField function is just missing a case statement for TagBoolean when dealing with any type?

diff --git a/src/encoding/asn1/asn1.go b/src/encoding/asn1/asn1.go
index 781ab87691..72d3f84f1c 100644
--- a/src/encoding/asn1/asn1.go
+++ b/src/encoding/asn1/asn1.go
@@ -726,6 +726,8 @@ func parseField(v reflect.Value, bytes []byte, initOffset int, params fieldParam
                                result = innerBytes
                        case TagBMPString:
                                result, err = parseBMPString(innerBytes)
+                       case TagBoolean:
+                               result, err = parseBool(innerBytes)
                        default:
                                // If we don't know how to handle the type, we just leave Value as nil.
                        }

@mauri870
Copy link
Member

cc @golang/security per https://dev.golang.org/owners

@mauri870 mauri870 added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 28, 2024
@seankhliao seankhliao changed the title encoding/asn1: Boolean tag not handled for any type encoding/asn1: bool values not unmarshaled into interface type Jun 29, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/595796 mentions this issue: encoding/asn1: unmarshal bool values correctly dealing with the ANY type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants