]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.10] runtime: don't check for String/Error methods in printany
authorIan Lance Taylor <iant@golang.org>
Fri, 23 Feb 2018 18:34:01 +0000 (10:34 -0800)
committerAndrew Bonventre <andybons@golang.org>
Thu, 29 Mar 2018 06:07:26 +0000 (06:07 +0000)
They have either already been called by preprintpanics, or they can
not be called safely because of the various conditions checked at the
start of gopanic.

Fixes #24059

Change-Id: I4a6233d12c9f7aaaee72f343257ea108bae79241
Reviewed-on: https://go-review.googlesource.com/96755
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-on: https://go-review.googlesource.com/102781
Run-TryBot: Andrew Bonventre <andybons@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/runtime/error.go
src/runtime/iface.go
src/runtime/panic.go

index 6048272e75d40ca83ae182bc3a6ebf8b81f0f32a..e1291e15435d53fc79b95f34c0e52065bc2f020d 100644 (file)
@@ -73,14 +73,12 @@ func typestring(x interface{}) string {
 }
 
 // printany prints an argument passed to panic.
+// If panic is called with a value that has a String or Error method,
+// it has already been converted into a string by preprintpanics.
 func printany(i interface{}) {
        switch v := i.(type) {
        case nil:
                print("nil")
-       case stringer:
-               print(v.String())
-       case error:
-               print(v.Error())
        case bool:
                print(v)
        case int:
index 7c5d3a05b25c97d63b06ee6a243fbc6d514fe944..bd6bc282f4eec3789e14220d5a83ca5b599cc047 100644 (file)
@@ -113,6 +113,14 @@ func (t *itabTableType) find(inter *interfacetype, typ *_type) *itab {
 // itabAdd adds the given itab to the itab hash table.
 // itabLock must be held.
 func itabAdd(m *itab) {
+       // Bugs can lead to calling this while mallocing is set,
+       // typically because this is called while panicing.
+       // Crash reliably, rather than only when we need to grow
+       // the hash table.
+       if getg().m.mallocing != 0 {
+               throw("malloc deadlock")
+       }
+
        t := itabTable
        if t.count >= 3*(t.size/4) { // 75% load factor
                // Grow hash table.
index c51948bd18e5805d745596237cf3a76adfd0933b..3d0c85f7f9327a72987f2681b443b96b9416c261 100644 (file)
@@ -389,7 +389,6 @@ func Goexit() {
 
 // Call all Error and String methods before freezing the world.
 // Used when crashing with panicking.
-// This must match types handled by printany.
 func preprintpanics(p *_panic) {
        defer func() {
                if recover() != nil {
@@ -415,8 +414,6 @@ func printpanics(p *_panic) {
                print("\t")
        }
        print("panic: ")
-       // Because of preprintpanics, p.arg cannot be an error or
-       // stringer, so this won't call into user code.
        printany(p.arg)
        if p.recovered {
                print(" [recovered]")