Skip to content

Commit

Permalink
format: fix another panic found via fuzzing
Browse files Browse the repository at this point in the history
A function can have non-nil but empty results,
which would lead to a sign.Results.List[-1] panic.
  • Loading branch information
mvdan committed Apr 3, 2022
1 parent b92582e commit 6105233
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ func (f *fumpter) applyPre(c *astutil.Cursor) {
}
}
handleMultiLine(sign.Params)
if sign.Results != nil {
if sign.Results != nil && len(sign.Results.List) > 0 {
lastResultLine := f.Line(sign.Results.List[len(sign.Results.List)-1].End())
isLastResultOnParamClosingLine := sign.Params != nil && lastResultLine == f.Line(sign.Params.Closing)
if !isLastResultOnParamClosingLine {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
go test fuzz v1
string("package A\nfunc A000000000(A000000000000,\nA00000000)(){\"\"}")
int8(62)
bool(true)

0 comments on commit 6105233

Please sign in to comment.