Debian Codegraph @

debian/patches/0001-change-debug-logging.patch

raw
1 Description: Gomuks logs by default in /tmp which opens a can of worms in terms of security
2 and also filling tmp dir with huge and verbose logs. This patch changes that behaviour to log
3 in ~/.local/state or XDG_STATE_DIR only when DEBUG=1
4 Author: Nilesh Patra <[email protected]>
5 Origin: upstream
6 Bug: https://github.com/tulir/gomuks/issues/429
7 Forwarded: https://github.com/tulir/gomuks/pull/430
8 Applied-Upstream: https://github.com/tulir/gomuks/commit/2b36ee373794ae4d4df4de95ed9e1428b9157dc9
9 Reviewed-by: Tulir Asokan
10 Last-Update: 2023-07-13
11 --- a/debug/debug.go
12 +++ b/debug/debug.go
13 @@ -22,7 +22,9 @@
14 "io"
15 "io/ioutil"
16 "os"
17 + "os/user"
18 "path/filepath"
19 + "runtime"
20 "runtime/debug"
21 "time"
22
23 @@ -30,11 +32,37 @@
24 )
25
26 var writer io.Writer
27 -var RecoverPrettyPanic bool
28 +var RecoverPrettyPanic bool = true
29 var DeadlockDetection bool
30 var WriteLogs bool
31 var OnRecover func()
32 -var LogDirectory = filepath.Join(os.TempDir(), "gomuks")
33 +var LogDirectory = GetUserDebugDir()
34 +
35 +func GetUserDebugDir() string {
36 + if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
37 + return filepath.Join(os.TempDir(), "gomuks-"+getUname())
38 + }
39 + // See https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
40 + if xdgStateHome := os.Getenv("XDG_STATE_HOME"); xdgStateHome != "" {
41 + return filepath.Join(xdgStateHome, "gomuks")
42 + }
43 + home := os.Getenv("HOME")
44 + if home == "" {
45 + fmt.Println("XDG_STATE_HOME and HOME are both unset")
46 + os.Exit(1)
47 + }
48 + return filepath.Join(home, ".local", "state", "gomuks")
49 +}
50 +
51 +func getUname() string {
52 + currUser, err := user.Current()
53 + if err != nil {
54 + fmt.Println(err)
55 + os.Exit(1)
56 + }
57 +
58 + return currUser.Username
59 +}
60
61 func Initialize() {
62 err := os.MkdirAll(LogDirectory, 0750)
63 --- a/main.go
64 +++ b/main.go
65 @@ -39,13 +39,10 @@
66 debug.LogDirectory = debugDir
67 }
68 debugLevel := strings.ToLower(os.Getenv("DEBUG"))
69 - if debugLevel != "0" && debugLevel != "f" && debugLevel != "false" {
70 - debug.WriteLogs = true
71 - debug.RecoverPrettyPanic = true
72 - }
73 if debugLevel == "1" || debugLevel == "t" || debugLevel == "true" {
74 debug.RecoverPrettyPanic = false
75 debug.DeadlockDetection = true
76 + debug.WriteLogs = true
77 }
78 debug.Initialize()
79 defer debug.Recover()