diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4fbbed6..9c4ccb8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,8 +15,8 @@ jobs: - name: Run Norminette run: make norm build: - name: build - runs-on: ubuntu-latest + name: build + check allowed functions + runs-on: macos-12 steps: - name: Checkout repository uses: actions/checkout@v4 @@ -28,6 +28,10 @@ jobs: run: make fclean - name: Build checker run: make bonus + - name: Build push_swap + run: make + - name: check allowed_functions + run: test/check_allowed_functions.sh unit_test: name: unit_test runs-on: macos-12 diff --git a/test/check_allowed_functions.sh b/test/check_allowed_functions.sh new file mode 100755 index 0000000..1bf2bac --- /dev/null +++ b/test/check_allowed_functions.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +check_binary_symbols() { + local binary="$1" + if [ ! -f $binary ]; then + echo "Error: Binary file '$binary' not found." + exit 1 + fi + local undefined_symbols=$(nm -u "$binary" | sed 's/^_*//') + for symbol in $undefined_symbols; do + if [[ ! " ${allowed_functions[@]} " =~ " ${symbol}" ]]; then + echo "Error: $binary: Disallowed function used: ${symbol}" + exit 1 + fi + done +} + +allowed_functions=("read" "write" "malloc" "free" "exit" "error" "dyld_stub_binder") + +# Check symbols for push_swap +check_binary_symbols "push_swap" + +# Check symbols for checker +check_binary_symbols "checker" + +echo "All used functions are allowed."