From 1b3bd3e16644959a15c4dd2bdde8061be2ceca28 Mon Sep 17 00:00:00 2001 From: rask24 <70057885+rask24@users.noreply.github.com> Date: Wed, 14 Feb 2024 20:48:49 +0900 Subject: [PATCH] check allowed functions (#38) * add shell script * refactor test * update ci * check * check2 * build on macos * fix ci * fix shell script --- .github/workflows/ci.yml | 8 ++++++-- test/check_allowed_functions.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100755 test/check_allowed_functions.sh 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."