fix: harden security resource lifecycles
This commit is contained in:
@@ -3,6 +3,7 @@ package binsnoop
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
@@ -20,3 +21,27 @@ func TestReadFileLimitedRejectsOversizedFile(t *testing.T) {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCarveUsesPrivatePermissions(t *testing.T) {
|
||||
if runtime.GOOS == "windows" {
|
||||
t.Skip("POSIX permission bits are not enforced on Windows")
|
||||
}
|
||||
path := filepath.Join(t.TempDir(), "private", "carved.bin")
|
||||
if err := Carve(path, []byte("secret"), 0, 6); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
info, err := os.Stat(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := info.Mode().Perm(); got != 0600 {
|
||||
t.Fatalf("carved file permissions = %04o, want 0600", got)
|
||||
}
|
||||
dirInfo, err := os.Stat(filepath.Dir(path))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := dirInfo.Mode().Perm(); got != 0700 {
|
||||
t.Fatalf("carve directory permissions = %04o, want 0700", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user