Skip to content

fmt: Panic within fmt.Sprintf() #64505

Closed as not planned
Closed as not planned
@williampeng-glean

Description

@williampeng-glean

Go version

go version go1.17.13 darwin/amd64

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

GO111MODULE=""
GOARCH="amd64"
GOBIN="/Users/williampeng/go/bin"
GOCACHE="/Users/williampeng/Library/Caches/go-build"
GOENV="/Users/williampeng/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/williampeng/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/williampeng/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/[email protected]/1.17.13/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/[email protected]/1.17.13/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.17.13"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/cw/msznbvjj1qb9125zkf1tffkc0000gn/T/go-build3610009397=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

func (ss *saltStoreImpl) saltAndHash(type string, value string) string {
	if len(value) == 0 {
		return ""
	}
	salt := ""
        // var typeToSalt map[string]string
	if ss.typeToSalt != nil {
		// If the salts are defined we use the salt for the key if exists and non-empty.
		if s, ok := ss.typeToSalt[type]; ok {
			salt = s
		}
	}
	if len(salt) == 0 {
		return Hash(value)
	}
	return Hash(fmt.Sprintf("%s%s", value, salt)) // <--- panic line
}

extra info, this function is run within a goroutine a few stacks deep

What did you expect to see?

no panics

What did you see instead?

invalid memory address or nil pointer dereference panic

Stacktrace (github.com/askscio/scio/go/** is our internal codebase):

routine.go:81: [CRITICAL_SCIO] Panic recovered (Workgroup): Recovery from go routine: runtime error: invalid memory address or nil pointer dereference
"Panic recovered (Workgroup): Recovery from go routine: runtime error: invalid memory address or nil pointer dereference" with stack
goroutine 6084916 [running]:
runtime/debug.Stack()
	GOROOT/src/runtime/debug/stack.go:24 +0x65
github.com/askscio/scio/go/slog.makeMultilineWithStack({0xc09a144200, 0x77})
	go/slog/slog.go:278 +0x7e
github.com/askscio/scio/go/slog.CriticalNoDowngrade({0x2337f30, 0xc06e6d5380}, {0x22fa5e0, 0xc09d05ec00})
	go/slog/slog.go:133 +0x36
github.com/askscio/scio/go/core/async.GoSafe_UpdateWorkgroup.func1.1()
	go/core/async/routine.go:81 +0x149
panic({0x1a0ae40, 0x38058b0})
	GOROOT/src/runtime/panic.go:1038 +0x215
fmt.(*buffer).writeString(...)
	GOROOT/src/fmt/print.go:82
fmt.(*fmt).padString(0xc022bab6c0, {0x0, 0xefc195})
	GOROOT/src/fmt/format.go:110 +0x247
fmt.(*fmt).fmtS(0x10, {0x0, 0xef8606})
	GOROOT/src/fmt/format.go:359 +0x35
fmt.(*pp).fmtString(0x10, {0x0, 0x1ee7aa8}, 0x2c9bfa28)
	GOROOT/src/fmt/print.go:446 +0xc5
fmt.(*pp).printArg(0xc022bab6c0, {0x193df40, 0xc09a279b40}, 0x73)
	GOROOT/src/fmt/print.go:694 +0x60c
fmt.(*pp).doPrintf(0xc022bab6c0, {0x1d84e9a, 0x4}, {0xc02c9bfb98, 0x4692e7, 0x40acb0})
	GOROOT/src/fmt/print.go:1026 +0x288
fmt.Sprintf({0x1d84e9a, 0x4}, {0xc02c9bfb98, 0x2, 0x2})
	GOROOT/src/fmt/print.go:219 +0x59
github.com/askscio/scio/go/core.(*saltStoreImpl).saltAndHash(0xc00184ffc0, 0x203039, {0x0, 0xc02c9bfc18})
	go/core/salt_store_impl.go:119 +0x154
github.com/askscio/scio/go/core.(*saltStoreImpl).GetQuery(0x40d547, {0x0, 0x203028})
	go/core/salt_store_impl.go:93 +0x29
github.com/askscio/scio/go/query_endpoint/logging.ScrubSessionInfo(0xc0013ce300, 0xc0ec3a0cd0)
	go/query_endpoint/logging/search.go:1015 +0xd7
github.com/askscio/scio/go/query_endpoint/logging.LogSearchResults({0x2337f30, 0xc06e6d5380}, 0xc09814ac00, 0xc02c9c1958, 0x0, {0xc0977d1d80, 0xe, 0x10}, {0xc147ac6b80, 0xe, ...}, ...)
	go/query_endpoint/logging/search.go:1848 +0x865
github.com/askscio/scio/go/query_endpoint/qna.logQnaResult({0x2337f30, 0xc06e6d5380}, 0xc09814ac00, 0xc09a27a7e0, 0x0)
	go/query_endpoint/qna/cwoqa.go:131 +0x14e
github.com/askscio/scio/go/query_endpoint/qna.ProcessResultsForCwoqa({0x2337f30, 0xc06e6d5380}, 0xc09814ac00, {0xc157938c80, 0xc0dc8a2990, 0x1a03940})
	go/query_endpoint/qna/cwoqa.go:48 +0x4b
github.com/askscio/scio/go/query_endpoint/backends.AnnotateResultsPostSearch({0x2337f30, 0xc06e6d5380}, 0xc0949e4b40, 0xc09814ac00, 0x1, {0x0, 0x0, 0x0}, 0xc001106e70, {0xc0dc0bba70, ...}, ...)
	go/query_endpoint/backends/documents.go:1040 +0x18eb
github.com/askscio/scio/go/query_endpoint/backends.documentBackend.GetResults.func1({0x2337f30, 0xc06e6d5380}, 0x0)
	go/query_endpoint/backends/documents.go:516 +0x175
github.com/askscio/scio/go/core/async.GoSafe_UpdateWorkgroup.func1({0x2337f30, 0xc06e6d5380}, 0xc0421ddfd0, 0x7a6606, 0xc0721a2ea0)
	go/core/async/routine.go:86 +0x89
created by github.com/askscio/scio/go/core/async.GoSafe_UpdateWorkgroup
	go/core/async/routine.go:74 +0x24f

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions