]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: prevent panic while formatting func(...T) with unknown T
authorJosh Bleecher Snyder <josharian@gmail.com>
Wed, 3 May 2017 23:37:03 +0000 (16:37 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Thu, 4 May 2017 00:37:17 +0000 (00:37 +0000)
Compile:

package p

var f = func(...A)

Before this CL:

x.go:3:13: type %!v(PANIC=runtime error: invalid memory address or nil pointer dereference) is not an expression
x.go:3:17: undefined: A

After this CL:

x.go:3:13: type func(...<T>) is not an expression
x.go:3:17: undefined: A

Found with go-fuzz.

Fixes #20233

Change-Id: Ibb232b3954c4091071440eba48b44c4022a8083f
Reviewed-on: https://go-review.googlesource.com/42610
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/fmt.go
test/fixedbugs/issue20233.go [new file with mode: 0644]

index 41502268a7bec46c22a8e900af2660616cb390b2..c0d82d8c165dc821bfcc16cd1c6262bd0e2ee078 100644 (file)
@@ -1754,7 +1754,11 @@ func fldconv(f *types.Field, flag FmtFlag, mode fmtMode, depth int) string {
 
        var typ string
        if f.Isddd() {
-               typ = "..." + tmodeString(f.Type.Elem(), mode, depth)
+               var et *types.Type
+               if f.Type != nil {
+                       et = f.Type.Elem()
+               }
+               typ = "..." + tmodeString(et, mode, depth)
        } else {
                typ = tmodeString(f.Type, mode, depth)
        }
diff --git a/test/fixedbugs/issue20233.go b/test/fixedbugs/issue20233.go
new file mode 100644 (file)
index 0000000..5734cf4
--- /dev/null
@@ -0,0 +1,11 @@
+// errorcheck
+
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Issue 20233: panic while formatting an error message
+
+package p
+
+var f = func(...A) // ERROR "type func(....*) is not an expression" ERROR "undefined: A"