Skip to content

Commit

Permalink
check allowed functions (#38)
Browse files Browse the repository at this point in the history
* add shell script

* refactor test

* update ci

* check

* check2

* build on macos

* fix ci

* fix shell script
  • Loading branch information
rask24 committed Feb 14, 2024
1 parent 2e906c4 commit 1b3bd3e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
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."

0 comments on commit 1b3bd3e

Please sign in to comment.