Module Name:    src
Committed By:   riastradh
Date:           Mon Aug  5 06:03:33 UTC 2024

Modified Files:
        src/tests/bin/pax: t_pax.sh

Log Message:
tests/bin/pax: Add some more cwd-related test cases.

PR bin/44498: tar(1) unnecessarily demands that getcwd() work


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/bin/pax/t_pax.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/bin/pax/t_pax.sh
diff -u src/tests/bin/pax/t_pax.sh:1.5 src/tests/bin/pax/t_pax.sh:1.6
--- src/tests/bin/pax/t_pax.sh:1.5	Mon Aug  5 04:05:59 2024
+++ src/tests/bin/pax/t_pax.sh	Mon Aug  5 06:03:33 2024
@@ -1,4 +1,4 @@
-# $NetBSD: t_pax.sh,v 1.5 2024/08/05 04:05:59 riastradh Exp $
+# $NetBSD: t_pax.sh,v 1.6 2024/08/05 06:03:33 riastradh Exp $
 #
 # Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -74,9 +74,81 @@ pr44498_body()
 	    sh -c '{ cd foo/bar && exec pax; } <baz.tar'
 }
 
+atf_test_case pr44498_copy
+pr44498_copy_head()
+{
+	atf_set "descr" \
+	    "Ensure pax insecure copy operation works without getcwd"
+	atf_set "require.user" "unprivileged"
+}
+pr44498_copy_body()
+{
+	mkdir foo foo/bar foo/bar/baz
+	chmod 111 foo
+	touch foo/bar/quux
+	atf_expect_fail 'PR bin/44498:' \
+	    'tar(1) unnecessarily demands that getcwd() work'
+	atf_check sh -c '{ cd foo/bar && exec pax -rw quux baz/.; }'
+}
+
+atf_test_case pr44498_insecureextract
+pr44498_insecureextract_head()
+{
+	atf_set "descr" \
+	    "Ensure pax insecure extract operation works without getcwd"
+	atf_set "require.user" "unprivileged"
+}
+pr44498_insecureextract_body()
+{
+	mkdir foo foo/bar baz
+	chmod 111 foo
+	touch baz/quux
+	atf_check pax -w -x ustar -f baz.tar baz
+	atf_expect_fail 'PR bin/44498:' \
+	    'tar(1) unnecessarily demands that getcwd() work'
+	atf_check sh -c '{ cd foo/bar && exec pax -r --insecure; } <baz.tar'
+}
+
+atf_test_case pr44498_listwd
+pr44498_listwd_head()
+{
+	atf_set "descr" "Ensure pax list operation works without working dir"
+	atf_set "require.user" "unprivileged"
+}
+pr44498_listwd_body()
+{
+	mkdir foo baz
+	chmod 111 foo
+	touch baz/quux
+	atf_check pax -w -x ustar -f baz.tar baz
+	atf_check -o 'inline:baz\nbaz/quux\n' \
+	    sh -c '{ cd foo && exec pax; } <baz.tar'
+}
+
+atf_test_case pr44498_write
+pr44498_write_head()
+{
+	atf_set "descr" "Ensure pax write operation works without getcwd"
+	atf_set "require.user" "unprivileged"
+}
+pr44498_write_body()
+{
+	mkdir foo foo/bar
+	touch foo/bar/quux
+	chmod 111 foo
+	atf_expect_fail 'PR bin/44498:' \
+	    'tar(1) unnecessarily demands that getcwd() work'
+	atf_check sh -c '{ cd foo/bar && pax -w -x ustar .; } >bar.tar'
+	atf_check -o 'inline:.\n./quux\n' pax -f bar.tar
+}
+
 atf_init_test_cases()
 {
 	atf_add_test_case append
 	atf_add_test_case pr41736
 	atf_add_test_case pr44498
+	atf_add_test_case pr44498_copy
+	atf_add_test_case pr44498_insecureextract
+	atf_add_test_case pr44498_listwd
+	atf_add_test_case pr44498_write
 }

Reply via email to