Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/driver/tempfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
// newTempFile returns a new output file in dir with the provided prefix and suffix.
func newTempFile(dir, prefix, suffix string) (*os.File, error) {
for index := 1; index < 10000; index++ {
switch f, err := os.OpenFile(filepath.Join(dir, fmt.Sprintf("%s%03d%s", prefix, index, suffix)), os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666); {
switch f, err := os.OpenFile(filepath.Join(dir, fmt.Sprintf("%s%03d%s", prefix, index, suffix)), os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600); {
case err == nil:
return f, nil
case !os.IsExist(err):
Expand Down
8 changes: 8 additions & 0 deletions internal/driver/tempfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package driver

import (
"os"
"runtime"
"sync"
"testing"
)
Expand Down Expand Up @@ -45,6 +46,13 @@ func TestNewTempFile(t *testing.T) {
break
}
names[name] = true
// Temp files can hold profile data, so they must not be accessible
// by group or other users.
if fi, err := os.Stat(name); err != nil {
t.Errorf("Stat(%s): got error %v, want no error", name, err)
} else if perm := fi.Mode().Perm(); runtime.GOOS != "windows" && perm&0077 != 0 {
t.Errorf("temp file %s has mode %#o, want no group/other access", name, perm)
}
}
if err := cleanupTempFiles(); err != nil {
t.Errorf("cleanupTempFiles(): got error %v, want no error", err)
Expand Down
Loading