]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: avoid endless loop if printing the panic value panics
authorIan Lance Taylor <iant@golang.org>
Wed, 5 Oct 2016 04:15:42 +0000 (21:15 -0700)
committerIan Lance Taylor <iant@golang.org>
Wed, 5 Oct 2016 13:13:27 +0000 (13:13 +0000)
Change-Id: I56de359a5ccdc0a10925cd372fa86534353c6ca0
Reviewed-on: https://go-review.googlesource.com/30358
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/runtime/crash_test.go
src/runtime/panic.go
src/runtime/testdata/testprog/deadlock.go

index 9d87957c2a5b7c6c6d1d93a3b4b82f1804e6826a..e352540ac228776f498ac292d944e955f15fb7dc 100644 (file)
@@ -444,6 +444,13 @@ func TestPanicDeadlockSyscall(t *testing.T) {
        testPanicDeadlock(t, "SyscallInPanic", "1\n2\npanic: 3\n\n")
 }
 
+func TestPanicLoop(t *testing.T) {
+       output := runTestProg(t, "testprog", "PanicLoop")
+       if want := "panic while printing panic value"; !strings.Contains(output, want) {
+               t.Errorf("output does not contain %q:\n%s", want, output)
+       }
+}
+
 func TestMemPprof(t *testing.T) {
        testenv.MustHaveGoRun(t)
 
index 9e456372b352b72b769bb175f127b885f8dff271..9e108cc437b475ce7edb6e8628a2c7f96d30258a 100644 (file)
@@ -376,6 +376,11 @@ func Goexit() {
 // Used when crashing with panicking.
 // This must match types handled by printany.
 func preprintpanics(p *_panic) {
+       defer func() {
+               if recover() != nil {
+                       throw("panic while printing panic value")
+               }
+       }()
        for p != nil {
                switch v := p.arg.(type) {
                case error:
index c938fcfb56913992fbaa1a1812696a0138c66380..ca2be579114a0757193c786218f7b75636ec983d 100644 (file)
@@ -32,6 +32,7 @@ func init() {
        register("PanicTraceback", PanicTraceback)
        register("GoschedInPanic", GoschedInPanic)
        register("SyscallInPanic", SyscallInPanic)
+       register("PanicLoop", PanicLoop)
 }
 
 func SimpleDeadlock() {
@@ -214,3 +215,13 @@ func pt2() {
        }()
        panic("hello")
 }
+
+type panicError struct{}
+
+func (*panicError) Error() string {
+       panic("double error")
+}
+
+func PanicLoop() {
+       panic(&panicError{})
+}