return ""
}
+proc path-sanitize {fn} {
+ if {[string index $fn 0] == "/"} {
+ puts stderr "absolute paths are forbidden"
+ exit 1
+ }
+ foreach e [file split $fn] {
+ if {$e == ".."} {
+ puts stderr "relative paths are forbidden"
+ exit 1
+ }
+ }
+}
+
proc assure-all-list-params-exist {opt {offset 0}} {
global Stash
set pth [find-opt-schema $opt]
while {[gets stdin line] >= 0} {
set fn [txtar-fn $line]
if {$fn == ""} {
- file mkdir $Stash/$fn
+ path-sanitize $line
+ file mkdir $Stash/$line
} else {
break
}
}
}
proc openfh {fn} {
- if {[string index $fn 0] == "/"} {
- puts stderr "absolute paths are forbidden"
- exit 1
- }
- foreach e [file split $fn] {
- if {$e == ".."} {
- puts stderr "relative paths are forbidden"
- exit 1
- }
- }
+ path-sanitize $fn
set bin no
if {[string range $fn [expr {[string length $fn]-7}] end] == ":base64"} {
set bin yes
addr=net/bar/addr/2001:db8::2:2345
test_expect_success "2001:db8::2:2345 add" "dsc add $addr >got"
+test_expect_success "baz net" "dsc add net/baz"
+
test_expect_success "note" 'dsc set sys/note "hello
world
"'
+net/bar/addr
+net/bar/addr/2001:DB8::1:2345
+net/bar/addr/2001:DB8::2:2345
++net/baz
+net/foo
+net/foo/addr
+net/foo/addr/2001:DB8::1:1234
EOF
test_expect_success "cmp" "test_cmp out expected"
test_expect_success "commit" "dsc commit"
+test_expect_success "diff" "dsc diff >out"
+test_expect_success "diff is empty" "! [ -s out ]"
test_expect_success "export" "dsc export >out"
cat >expected <<EOF
-- .dirs --
net/bar/addr
net/bar/addr/2001:DB8::1:2345
net/bar/addr/2001:DB8::2:2345
+net/baz
net/foo
net/foo/addr
net/foo/addr/2001:DB8::1:1234
EOF
test_expect_success "cmp" "test_cmp out expected"
+rm -r $DSC_STASH
+test_expect_success "import" "dsc import <out"
+test_expect_success "diff" "dsc diff >out"
+cat out
+test_expect_success "diff is empty" "! [ -s out ]"
+
test_done
test_expect_success "import rel msg" \
'[ "$(cat out)" = "relative paths are forbidden" ]'
+cat >in <<EOF
+-- .dirs --
+/abs/path
+gotcha
+EOF
+test_expect_success "import abs" "! dsc import <in >out 2>&1"
+test_expect_success "import abs msg" \
+ '[ "$(cat out)" = "absolute paths are forbidden" ]'
+
+cat >in <<EOF
+-- .dirs --
+path/../rel
+EOF
+test_expect_success "import rel" "! dsc import <in >out 2>&1"
+test_expect_success "import rel msg" \
+ '[ "$(cat out)" = "relative paths are forbidden" ]'
+
test_done