Просмотр исходного кода

Fix panicwrap stacks on Go 1.19.10+

Rod Hynes 2 лет назад
Родитель
Сommit
927109f4b2
1 измененных файлов с 11 добавлено и 0 удалено
  1. 11 0
      Server/main.go

+ 11 - 0
Server/main.go

@@ -26,6 +26,7 @@ import (
 	"io"
 	"io/ioutil"
 	"os"
+	"runtime/debug"
 	"strconv"
 	"strings"
 	"syscall"
@@ -248,6 +249,16 @@ func main() {
 		}
 		// Else, this is the child process.
 
+		// As of Go 1.19.10, programs with Linux capabilities or setuid do not
+		// dump panic stacks by default. See:
+		// https://github.com/golang/go/commit/a7b1cd452ddc69a6606c2f35ac5786dc892e62cb.
+		// To restore panic stacks, we call SetTraceback("single"), restoring
+		// the default GOTRACKBACK value. The server program is run as a
+		// non-privileged user and with CAP_NET capabilities; neither the
+		// panic stack traces nor register dumps are expected to expose any
+		// unexpected sensitive information.
+		debug.SetTraceback("single")
+
 		err = server.RunServices(configJSON)
 		if err != nil {
 			fmt.Printf("run failed: %s\n", err)