Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check allowed functions #38

Merged
merged 8 commits into from
Feb 14, 2024
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
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
26 changes: 26 additions & 0 deletions test/check_allowed_functions.sh
Original file line number Diff line number Diff line change
@@ -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."