carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package hostbox
2
3import (
4 "os"
5 "path/filepath"
6 "testing"
7)
8
9func TestClaimReviewJournalsRefusePlantedSymlinks(t *testing.T) {
10 for _, kind := range []string{"launch", "inventory"} {
11 for _, suffix := range []string{"", "-wal", "-shm"} {
12 t.Run(kind+suffix, func(t *testing.T) {
13 dir := t.TempDir()
14 path := filepath.Join(dir, "journal.db")
15 victim := filepath.Join(dir, "victim")
16 if err := os.Symlink(victim, path+suffix); err != nil {
17 t.Fatal(err)
18 }
19 var err error
20 if kind == "launch" {
21 var j *LaunchJournal
22 j, err = OpenLaunchJournal(path)
23 if err == nil {
24 j.Close()
25 }
26 } else {
27 var j *StopInventoryDB
28 j, err = OpenStopInventoryDB(path)
29 if err == nil {
30 j.Close()
31 }
32 }
33 if err == nil {
34 t.Error("planted symlink accepted")
35 }
36 if _, err := os.Lstat(victim); !os.IsNotExist(err) {
37 t.Fatalf("SQLite touched symlink target: %v", err)
38 }
39 })
40 }
41 }
42}
43