Skip to content

Commit

Permalink
Set umask=0 when creating unix sockets
Browse files Browse the repository at this point in the history
Signed-off-by: eternal-flame-AD <[email protected]>
  • Loading branch information
eternal-flame-AD committed Nov 22, 2024
1 parent cc7da2a commit 2bc026a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
12 changes: 8 additions & 4 deletions runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,15 @@ func startListening(connectionType, listenAddr string, port, keepAlive int) (net
network, addr := getNetworkAndAddr(listenAddr, port)
lc := net.ListenConfig{KeepAlive: time.Duration(keepAlive) * time.Second}

l, err := lc.Listen(context.Background(), network, addr)
if err == nil {
fmt.Println("Started listening for", connectionType, "on", l.Addr().Network(), l.Addr().String())
var l net.Listener
if err := withUmask(0, func() (err error) {
l, err = lc.Listen(context.Background(), network, addr)
return err
}); err != nil {
return nil, err

Check warning on line 85 in runner/runner.go

View check run for this annotation

Codecov / codecov/patch

runner/runner.go#L80-L85

Added lines #L80 - L85 were not covered by tests
}
return l, err
fmt.Println("Started listening for", connectionType, "on", l.Addr().Network(), l.Addr().String())
return l, nil

Check warning on line 88 in runner/runner.go

View check run for this annotation

Codecov / codecov/patch

runner/runner.go#L87-L88

Added lines #L87 - L88 were not covered by tests
}

func getNetworkAndAddr(listenAddr string, port int) (string, string) {
Expand Down
11 changes: 11 additions & 0 deletions runner/umask.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//go:build unix

package runner

import "syscall"

func withUmask(mask int, f func() error) error {
oldmask := syscall.Umask(mask)
defer syscall.Umask(oldmask)
return f()

Check warning on line 10 in runner/umask.go

View check run for this annotation

Codecov / codecov/patch

runner/umask.go#L7-L10

Added lines #L7 - L10 were not covered by tests
}
7 changes: 7 additions & 0 deletions runner/umask_fallback.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build !unix

package runner

func withUmask(_ int, f func() error) error {
return f()
}

0 comments on commit 2bc026a

Please sign in to comment.