From 15487abace3cf76d1dd9a8223219af8fed0d124b Mon Sep 17 00:00:00 2001 From: rask24 Date: Wed, 14 Feb 2024 20:19:34 +0900 Subject: [PATCH 1/8] add shell script --- test/check_allowed_functions.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 test/check_allowed_functions.sh diff --git a/test/check_allowed_functions.sh b/test/check_allowed_functions.sh new file mode 100755 index 0000000..df3b776 --- /dev/null +++ b/test/check_allowed_functions.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +allowed_functions=("read" "write" "malloc" "free" "exit" "error") + +# push_swap +undefined_symbols=$(nm -u push_swap | tr -d '_') +for symbol in $undefined_symbols; do + if [[ ! " ${allowed_functions[@]} " =~ " ${symbol} " ]]; then + echo "Error: push_swap: Disallowed function used: ${symbol}" + exit 1 + fi +done + +# checker +undefined_symbols=$(nm -u checker | tr -d '_') +for symbol in $undefined_symbols; do + if [[ ! " ${allowed_functions[@]} " =~ " ${symbol} " ]]; then + echo "Error: checker: Disallowed function used: ${symbol}" + exit 1 + fi +done + +echo "All used functions are allowed." From 6148583d758619f0fbcc9796e329a6ad22fe4864 Mon Sep 17 00:00:00 2001 From: rask24 Date: Wed, 14 Feb 2024 20:27:31 +0900 Subject: [PATCH 2/8] refactor test --- test/check_allowed_functions.sh | 35 ++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/test/check_allowed_functions.sh b/test/check_allowed_functions.sh index df3b776..ecbc1da 100755 --- a/test/check_allowed_functions.sh +++ b/test/check_allowed_functions.sh @@ -1,23 +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" | tr -d '_') + 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") -# push_swap -undefined_symbols=$(nm -u push_swap | tr -d '_') -for symbol in $undefined_symbols; do - if [[ ! " ${allowed_functions[@]} " =~ " ${symbol} " ]]; then - echo "Error: push_swap: Disallowed function used: ${symbol}" - exit 1 - fi -done +# Check symbols for push_swap +check_binary_symbols "push_swap" -# checker -undefined_symbols=$(nm -u checker | tr -d '_') -for symbol in $undefined_symbols; do - if [[ ! " ${allowed_functions[@]} " =~ " ${symbol} " ]]; then - echo "Error: checker: Disallowed function used: ${symbol}" - exit 1 - fi -done +# Check symbols for checker +check_binary_symbols "checker" echo "All used functions are allowed." From f43259a2dc0b6598e8d7a0b8aa7e0c503b0646b7 Mon Sep 17 00:00:00 2001 From: rask24 Date: Wed, 14 Feb 2024 20:29:45 +0900 Subject: [PATCH 3/8] update ci --- .github/workflows/ci.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4fbbed6..68c0dea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: - name: Run Norminette run: make norm build: - name: build + name: Build + Check allowed functions runs-on: ubuntu-latest steps: - name: Checkout repository @@ -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 From 730a4986c214367cd557d50fd0a9350f425e9dfa Mon Sep 17 00:00:00 2001 From: rask24 Date: Wed, 14 Feb 2024 20:32:19 +0900 Subject: [PATCH 4/8] check --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 68c0dea..a1fa78a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,6 +30,8 @@ jobs: run: make bonus - name: Build push_swap run: make + - name: check + run: nm push_swap && nm checker - name: check allowed_functions run: test/check_allowed_functions.sh unit_test: From 04b349d80d7d59f29a7a7b554978046ad6ff20e2 Mon Sep 17 00:00:00 2001 From: rask24 Date: Wed, 14 Feb 2024 20:34:51 +0900 Subject: [PATCH 5/8] check2 --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a1fa78a..35e3b4f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,9 @@ jobs: - name: Build push_swap run: make - name: check - run: nm push_swap && nm checker + run: nm -u push_swap + - name: check2 + run: nm -u checker - name: check allowed_functions run: test/check_allowed_functions.sh unit_test: From b9511749eb4ac069b8f8b79f212886ec0b6b2cf1 Mon Sep 17 00:00:00 2001 From: rask24 Date: Wed, 14 Feb 2024 20:36:15 +0900 Subject: [PATCH 6/8] build on macos --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 35e3b4f..bc0d181 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: run: make norm build: name: Build + Check allowed functions - runs-on: ubuntu-latest + runs-on: macos-12 steps: - name: Checkout repository uses: actions/checkout@v4 From 4d5588e9c88344d952870fcb3af4085af83c86df Mon Sep 17 00:00:00 2001 From: rask24 Date: Wed, 14 Feb 2024 20:43:06 +0900 Subject: [PATCH 7/8] fix ci --- .github/workflows/ci.yml | 6 +----- test/check_allowed_functions.sh | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bc0d181..9c4ccb8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: - name: Run Norminette run: make norm build: - name: Build + Check allowed functions + name: build + check allowed functions runs-on: macos-12 steps: - name: Checkout repository @@ -30,10 +30,6 @@ jobs: run: make bonus - name: Build push_swap run: make - - name: check - run: nm -u push_swap - - name: check2 - run: nm -u checker - name: check allowed_functions run: test/check_allowed_functions.sh unit_test: diff --git a/test/check_allowed_functions.sh b/test/check_allowed_functions.sh index ecbc1da..a76c4f7 100755 --- a/test/check_allowed_functions.sh +++ b/test/check_allowed_functions.sh @@ -15,7 +15,7 @@ check_binary_symbols() { done } -allowed_functions=("read" "write" "malloc" "free" "exit" "error") +allowed_functions=("read" "write" "malloc" "free" "exit" "error" "dyld_stub_binder") # Check symbols for push_swap check_binary_symbols "push_swap" From 6f1ee8b50aa063381cb4d6c980438a1b19a051c9 Mon Sep 17 00:00:00 2001 From: rask24 Date: Wed, 14 Feb 2024 20:47:00 +0900 Subject: [PATCH 8/8] fix shell script --- test/check_allowed_functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/check_allowed_functions.sh b/test/check_allowed_functions.sh index a76c4f7..1bf2bac 100755 --- a/test/check_allowed_functions.sh +++ b/test/check_allowed_functions.sh @@ -6,7 +6,7 @@ check_binary_symbols() { echo "Error: Binary file '$binary' not found." exit 1 fi - local undefined_symbols=$(nm -u "$binary" | tr -d '_') + 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}"