From 2ff902e9151a22dfd295ae12f498a800dd516cc1 Mon Sep 17 00:00:00 2001 From: sabi789 Date: Mon, 27 Apr 2026 07:34:35 -0400 Subject: [PATCH 1/2] Add rbash test Signed-off-by: sabi789 --- stable-patches/MANIFEST.patch | 21 ++++ stable-patches/tests/rbash_test.patch | 141 ++++++++++++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100644 stable-patches/MANIFEST.patch create mode 100644 stable-patches/tests/rbash_test.patch diff --git a/stable-patches/MANIFEST.patch b/stable-patches/MANIFEST.patch new file mode 100644 index 0000000..b090324 --- /dev/null +++ b/stable-patches/MANIFEST.patch @@ -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 diff --git a/stable-patches/tests/rbash_test.patch b/stable-patches/tests/rbash_test.patch new file mode 100644 index 0000000..770b4b0 --- /dev/null +++ b/stable-patches/tests/rbash_test.patch @@ -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 ++ rbash -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 /tmp" ++ ++# 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 /" "/bin/ls" ++ ++# Test 4: Cannot redirect output ++test_restriction "output redirection" "echo test > /tmp/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=/tmp/env" ++ ++# Test 8: Cannot modify BASH_ENV variable ++test_restriction "BASH_ENV modification" "BASH_ENV=/tmp/bashenv" ++ ++# Test 9: Allowed operation - simple echo should work ++echo "Testing: allowed operation (echo)" ++rbash -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 "✓ All rbash restriction tests passed!" ++ exit 0 ++else ++ echo "✗ 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: 127) ++ ++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 ++ ++✓ 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} From a7812964bcd29ee7573bb00a078a15c173e8bfcb Mon Sep 17 00:00:00 2001 From: sabi789 Date: Tue, 28 Apr 2026 05:46:18 -0400 Subject: [PATCH 2/2] Rework of comments Signed-off-by: sabi789 --- stable-patches/MANIFEST.patch | 6 ++-- stable-patches/tests/rbash_test.patch | 46 +++++++++++++-------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/stable-patches/MANIFEST.patch b/stable-patches/MANIFEST.patch index b090324..5d30b8c 100644 --- a/stable-patches/MANIFEST.patch +++ b/stable-patches/MANIFEST.patch @@ -6,8 +6,8 @@ index 985d179..2a1cd25 100644 tests/quotearray3.sub f tests/quotearray4.sub f tests/quotearray5.sub f -+tests/rbash.tests f -+tests/rbash.right f ++tests/rbash.tests f ++tests/rbash.right f tests/read.tests f tests/read.right f tests/read1.sub f @@ -15,7 +15,7 @@ index 985d179..2a1cd25 100644 tests/run-procsub f tests/run-quote f tests/run-quotearray f -+tests/run-rbash f ++tests/run-rbash f tests/run-read f tests/run-redir f tests/run-rhs-exp f diff --git a/stable-patches/tests/rbash_test.patch b/stable-patches/tests/rbash_test.patch index 770b4b0..f949c94 100644 --- a/stable-patches/tests/rbash_test.patch +++ b/stable-patches/tests/rbash_test.patch @@ -26,31 +26,31 @@ index 0000000..a9c88cc + echo "Testing: $test_name" + + # Run command in rbash and capture exit code -+ rbash -c "$command" 2>/dev/null ++ ${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)" ++ echo " [PASS]: Command properly restricted (exit code: $exit_code)" + ((PASSED++)) + else -+ echo " ✗ FAIL: Command should have been restricted but succeeded" ++ echo " [FAIL]: Command should have been restricted but succeeded" + ((FAILED++)) + fi + echo "" +} + +# Test 1: Cannot change directory -+test_restriction "cd restriction" "cd /tmp" ++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 /" "/bin/ls" ++test_restriction "command with /" "/usr/bin/env" + +# Test 4: Cannot redirect output -+test_restriction "output redirection" "echo test > /tmp/test.txt" ++test_restriction "output redirection" "echo test > test.txt" + +# Test 5: Cannot use exec builtin +test_restriction "exec builtin" "exec ls" @@ -59,19 +59,19 @@ index 0000000..a9c88cc +test_restriction "SHELL modification" "SHELL=/bin/sh" + +# Test 7: Cannot modify ENV variable -+test_restriction "ENV modification" "ENV=/tmp/env" ++test_restriction "ENV modification" "ENV=/etc/profile" + +# Test 8: Cannot modify BASH_ENV variable -+test_restriction "BASH_ENV modification" "BASH_ENV=/tmp/bashenv" ++test_restriction "BASH_ENV modification" "BASH_ENV=/etc/profile" + +# Test 9: Allowed operation - simple echo should work +echo "Testing: allowed operation (echo)" -+rbash -c "echo 'Hello from rbash'" >/dev/null 2>&1 ++${THIS_SH} -r -c "echo 'Hello from rbash'" >/dev/null 2>&1 +if [ $? -eq 0 ]; then -+ echo " ✓ PASS: Allowed command works correctly" ++ echo " [PASS]: Allowed command works correctly" + ((PASSED++)) +else -+ echo " ✗ FAIL: Allowed command failed" ++ echo " [FAIL]: Allowed command failed" + ((FAILED++)) +fi +echo "" @@ -84,10 +84,10 @@ index 0000000..a9c88cc +echo "" + +if [ $FAILED -eq 0 ]; then -+ echo "✓ All rbash restriction tests passed!" ++ echo "[PASS] All rbash restriction tests passed!" + exit 0 +else -+ echo "✗ Some rbash restriction tests failed!" ++ echo "[FAIL] Some rbash restriction tests failed!" + exit 1 +fi diff --git a/tests/rbash.right b/tests/rbash.right @@ -99,38 +99,38 @@ index 0000000..e831f1d +=== Restricted Bash (rbash) Test Suite === + +Testing: cd restriction -+ ✓ PASS: Command properly restricted (exit code: 1) ++ [PASS]: Command properly restricted (exit code: 1) + +Testing: PATH modification -+ ✓ PASS: Command properly restricted (exit code: 1) ++ [PASS]: Command properly restricted (exit code: 1) + +Testing: command with / -+ ✓ PASS: Command properly restricted (exit code: 127) ++ [PASS]: Command properly restricted (exit code: 1) + +Testing: output redirection -+ ✓ PASS: Command properly restricted (exit code: 1) ++ [PASS]: Command properly restricted (exit code: 1) + +Testing: exec builtin -+ ✓ PASS: Command properly restricted (exit code: 1) ++ [PASS]: Command properly restricted (exit code: 1) + +Testing: SHELL modification -+ ✓ PASS: Command properly restricted (exit code: 1) ++ [PASS]: Command properly restricted (exit code: 1) + +Testing: ENV modification -+ ✓ PASS: Command properly restricted (exit code: 1) ++ [PASS]: Command properly restricted (exit code: 1) + +Testing: BASH_ENV modification -+ ✓ PASS: Command properly restricted (exit code: 1) ++ [PASS]: Command properly restricted (exit code: 1) + +Testing: allowed operation (echo) -+ ✓ PASS: Allowed command works correctly ++ [PASS]: Allowed command works correctly + +=== Test Summary === +Total tests: 9 +Passed: 9 +Failed: 0 + -+✓ All rbash restriction tests passed! ++[PASS] All rbash restriction tests passed! diff --git a/tests/run-rbash b/tests/run-rbash new file mode 100644 index 0000000..f80b7f2