Skip to content
Merged
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
21 changes: 21 additions & 0 deletions stable-patches/MANIFEST.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
diff --git a/MANIFEST b/MANIFEST
index 985d179..2a1cd25 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -1455,6 +1455,8 @@ tests/quotearray2.sub f
tests/quotearray3.sub f
tests/quotearray4.sub f
tests/quotearray5.sub f
+tests/rbash.tests f
+tests/rbash.right f
tests/read.tests f
tests/read.right f
tests/read1.sub f
@@ -1565,6 +1567,7 @@ tests/run-printf f
tests/run-procsub f
tests/run-quote f
tests/run-quotearray f
+tests/run-rbash f
tests/run-read f
tests/run-redir f
tests/run-rhs-exp f
141 changes: 141 additions & 0 deletions stable-patches/tests/rbash_test.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
diff --git a/tests/rbash.tests b/tests/rbash.tests
new file mode 100644
index 0000000..a9c88cc
--- /dev/null
+++ b/tests/rbash.tests
@@ -0,0 +1,86 @@
+#!/bin/bash
+#
+# test_rbash.sh - Simple test script for restricted bash (rbash)
+#
+# This script tests basic rbash restrictions to verify the bashport
+# implementation is working correctly.
+#
+
+echo "=== Restricted Bash (rbash) Test Suite ==="
+echo ""
+
+PASSED=0
+FAILED=0
+
+# Helper function to test a restriction
+test_restriction() {
+ local test_name="$1"
+ local command="$2"
+
+ echo "Testing: $test_name"
+
+ # Run command in rbash and capture exit code
+ ${THIS_SH} -r -c "$command" 2>/dev/null
+ local exit_code=$?
+
+ # For restricted operations, we expect non-zero exit code
+ if [ $exit_code -ne 0 ]; then
+ echo " [PASS]: Command properly restricted (exit code: $exit_code)"
+ ((PASSED++))
+ else
+ echo " [FAIL]: Command should have been restricted but succeeded"
+ ((FAILED++))
+ fi
+ echo ""
+}
+
+# Test 1: Cannot change directory
+test_restriction "cd restriction" "cd /"
+
+# Test 2: Cannot modify PATH
+test_restriction "PATH modification" "PATH=/bin:/usr/bin"
+
+# Test 3: Cannot use commands with absolute path
+test_restriction "command with /" "/usr/bin/env"
+
+# Test 4: Cannot redirect output
+test_restriction "output redirection" "echo test > test.txt"
+
+# Test 5: Cannot use exec builtin
+test_restriction "exec builtin" "exec ls"
+
+# Test 6: Cannot modify SHELL variable
+test_restriction "SHELL modification" "SHELL=/bin/sh"
+
+# Test 7: Cannot modify ENV variable
+test_restriction "ENV modification" "ENV=/etc/profile"
+
+# Test 8: Cannot modify BASH_ENV variable
+test_restriction "BASH_ENV modification" "BASH_ENV=/etc/profile"
+
+# Test 9: Allowed operation - simple echo should work
+echo "Testing: allowed operation (echo)"
+${THIS_SH} -r -c "echo 'Hello from rbash'" >/dev/null 2>&1
+if [ $? -eq 0 ]; then
+ echo " [PASS]: Allowed command works correctly"
+ ((PASSED++))
+else
+ echo " [FAIL]: Allowed command failed"
+ ((FAILED++))
+fi
+echo ""
+
+# Summary
+echo "=== Test Summary ==="
+echo "Total tests: $((PASSED + FAILED))"
+echo "Passed: $PASSED"
+echo "Failed: $FAILED"
+echo ""
+
+if [ $FAILED -eq 0 ]; then
+ echo "[PASS] All rbash restriction tests passed!"
+ exit 0
+else
+ echo "[FAIL] Some rbash restriction tests failed!"
+ exit 1
+fi
diff --git a/tests/rbash.right b/tests/rbash.right
new file mode 100644
index 0000000..e831f1d
--- /dev/null
+++ b/tests/rbash.right
@@ -0,0 +1,35 @@
+=== Restricted Bash (rbash) Test Suite ===
+
+Testing: cd restriction
+ [PASS]: Command properly restricted (exit code: 1)
+
+Testing: PATH modification
+ [PASS]: Command properly restricted (exit code: 1)
+
+Testing: command with /
+ [PASS]: Command properly restricted (exit code: 1)
+
+Testing: output redirection
+ [PASS]: Command properly restricted (exit code: 1)
+
+Testing: exec builtin
+ [PASS]: Command properly restricted (exit code: 1)
+
+Testing: SHELL modification
+ [PASS]: Command properly restricted (exit code: 1)
+
+Testing: ENV modification
+ [PASS]: Command properly restricted (exit code: 1)
+
+Testing: BASH_ENV modification
+ [PASS]: Command properly restricted (exit code: 1)
+
+Testing: allowed operation (echo)
+ [PASS]: Allowed command works correctly
+
+=== Test Summary ===
+Total tests: 9
+Passed: 9
+Failed: 0
+
+[PASS] All rbash restriction tests passed!
diff --git a/tests/run-rbash b/tests/run-rbash
new file mode 100644
index 0000000..f80b7f2
--- /dev/null
+++ b/tests/run-rbash
@@ -0,0 +1,2 @@
+${THIS_SH} ./rbash.tests > ${BASH_TSTOUT} 2>&1
+diff ${BASH_TSTOUT} rbash.right | tee rbash.output && rm -f ${BASH_TSTOUT}
Loading