From 28e7f6b2ff473c435cae2a4791261aee66413f2d Mon Sep 17 00:00:00 2001 From: polyfloyd Date: Thu, 29 Sep 2022 20:41:20 +0200 Subject: [PATCH] Fix missing bounds check in errorf verb matching (fixes #29) --- errorlint/printf.go | 3 +++ errorlint/testdata/src/issues/github-29.go | 8 ++++++++ 2 files changed, 11 insertions(+) create mode 100644 errorlint/testdata/src/issues/github-29.go diff --git a/errorlint/printf.go b/errorlint/printf.go index f3d81b5..d9a935f 100644 --- a/errorlint/printf.go +++ b/errorlint/printf.go @@ -14,6 +14,9 @@ func verbOrder(verbs []verb, numArgs int) [][]verb { if v.index != -1 { i = v.index - 1 } + if i >= len(orderedVerbs) { + continue + } orderedVerbs[i] = append(orderedVerbs[i], v) verbs = verbs[1:] i++ diff --git a/errorlint/testdata/src/issues/github-29.go b/errorlint/testdata/src/issues/github-29.go new file mode 100644 index 0000000..61eeb53 --- /dev/null +++ b/errorlint/testdata/src/issues/github-29.go @@ -0,0 +1,8 @@ +package issues + +import "fmt" + +func Issue29() { + err := fmt.Errorf("%v %#[2]v", struct{ string }{}) + fmt.Println(err) +}