Skip to content

fmt: Scanf accepts invalid boolean values #43306

@andydotxyz

Description

@andydotxyz

What version of Go are you using (go version)?

$ go version
1.15.5

Does this issue reproduce with the latest release?

Not checked 1.15.6 yet, sorry

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/andy/Library/Caches/go-build"
GOENV="/Users/andy/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/andy/Code/Go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/andy/Code/Go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.15.5/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.15.5/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/andy/Code/Go/src/fyne.io/fyne/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/rk/wps4hdmx73ldvbq2dbprd_3c0000gn/T/go-build914664370=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Tried to parse certain invalid boolean values using fmt.Sscanf and a "%t" format.
Using the following code to test certain input strings

	err, n := fmt.Sscanf("true", "%t", &val)
	fmt.Println("true:", val, n, err)

What did you expect to see?

true: true 1
tBu: true syntax error scanning boolean 0
trB: true syntax error scanning boolean 0
false: false 1
fRl: false syntax error scanning boolean 0
faR: false syntax error scanning boolean 0
foo: false syntax error scanning boolean 0

What did you see instead?

true: true 1
tBu: true 1
trB: true syntax error scanning boolean 0
false: false 1
fRl: false 1
faR: false syntax error scanning boolean 0
foo: false 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions