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

Usage of non-portable strndup in cstest #2517

Open
thestr4ng3r opened this issue Oct 15, 2024 · 1 comment
Open

Usage of non-portable strndup in cstest #2517

thestr4ng3r opened this issue Oct 15, 2024 · 1 comment

Comments

@thestr4ng3r
Copy link
Contributor

Work environment

Questions Answers
OS/arch/bits Mac OS X 10.5
Architecture powerpc
Source of Capstone Source with -DCAPSTONE_BUILD_CSTEST=ON
Version/git commit next, 5bd05e3

Expected behavior

cstest (-DCAPSTONE_BUILD_CSTEST=ON) compiles

Actual behavior

[98/175] Building C object suite/cstest/CMakeFiles/libcstest.dir/src/helper.c.o
FAILED: suite/cstest/CMakeFiles/libcstest.dir/src/helper.c.o
/opt/local/bin/gcc-mp-7 -DCAPSTONE_AARCH64_SUPPORT -DCAPSTONE_ALPHA_SUPPORT -DCAPSTONE_ARM_SUPPORT -DCAPSTONE_BPF_SUPPORT -DCAPSTONE_DEBUG -DCAPSTONE_EVM_SUPPORT -DCAPSTONE_HAS_AARCH64 -DCAPSTONE_HAS_ALPHA -DCAPSTONE_HAS_ARM -DCAPSTONE_HAS_BPF -DCAPSTONE_HAS_EVM -DCAPSTONE_HAS_HPPA -DCAPSTONE_HAS_LOONGARCH -DCAPSTONE_HAS_M680X -DCAPSTONE_HAS_M68K -DCAPSTONE_HAS_MIPS -DCAPSTONE_HAS_MOS65XX -DCAPSTONE_HAS_POWERPC -DCAPSTONE_HAS_RISCV -DCAPSTONE_HAS_SH -DCAPSTONE_HAS_SPARC -DCAPSTONE_HAS_SYSTEMZ -DCAPSTONE_HAS_TMS320C64X -DCAPSTONE_HAS_TRICORE -DCAPSTONE_HAS_WASM -DCAPSTONE_HAS_X86 -DCAPSTONE_HAS_XCORE -DCAPSTONE_HAS_XTENSA -DCAPSTONE_HPPA_SUPPORT -DCAPSTONE_LOONGARCH_SUPPORT -DCAPSTONE_M680X_SUPPORT -DCAPSTONE_M68K_SUPPORT -DCAPSTONE_MIPS_SUPPORT -DCAPSTONE_MOS65XX_SUPPORT -DCAPSTONE_PPC_SUPPORT -DCAPSTONE_RISCV_SUPPORT -DCAPSTONE_SH_SUPPORT -DCAPSTONE_SPARC_SUPPORT -DCAPSTONE_SYSTEMZ_SUPPORT -DCAPSTONE_TMS320C64X_SUPPORT -DCAPSTONE_TRICORE_SUPPORT -DCAPSTONE_USE_SYS_DYN_MEM -DCAPSTONE_WASM_SUPPORT -DCAPSTONE_X86_SUPPORT -DCAPSTONE_XCORE_SUPPORT -DCAPSTONE_XTENSA_SUPPORT -I"/Users/florian/dev/capstone/include>" -I/Users/florian/dev/capstone/suite/cstest/include -I/Users/florian/dev/capstone/build/suite/cstest/extern/src/cmocka_ext/include -I/Users/florian/dev/capstone/build/suite/cstest/extern/src/libcyaml_ext/include -I/Users/florian/dev/capstone/include -g -Werror -Wall -Warray-bounds -Wshift-negative-value -Wreturn-type -Wformat -Wmissing-braces -Wunused-function -Wunused-variable -Wparentheses -Wint-in-bool-context -Wmisleading-indentation -Wno-maybe-uninitialized -Wshadow=local -MD -MT suite/cstest/CMakeFiles/libcstest.dir/src/helper.c.o -MF suite/cstest/CMakeFiles/libcstest.dir/src/helper.c.o.d -o suite/cstest/CMakeFiles/libcstest.dir/src/helper.c.o -c /Users/florian/dev/capstone/suite/cstest/src/helper.c
/Users/florian/dev/capstone/suite/cstest/src/helper.c: In function 'replace_hex':
/Users/florian/dev/capstone/suite/cstest/src/helper.c:55:13: error: implicit declaration of function 'strndup' [-Werror=implicit-function-declaration]
   tmp_tmp = strndup(tmp, orig_found - tmp);
             ^~~~~~~
/Users/florian/dev/capstone/suite/cstest/src/helper.c:55:13: error: incompatible implicit declaration of built-in function 'strndup' [-Werror]
/Users/florian/dev/capstone/suite/cstest/src/helper.c: In function 'replace_negative':
/Users/florian/dev/capstone/suite/cstest/src/helper.c:120:13: error: incompatible implicit declaration of built-in function 'strndup' [-Werror]
   tmp_tmp = strndup(tmp, orig_found - tmp);
             ^~~~~~~
cc1: all warnings being treated as errors
[100/175] Linking C static library libcapstone.a
ninja: build stopped: subcommand failed.

Steps to reproduce the behavior

Compile with cmake and cstest enabled (-DCAPSTONE_BUILD_CSTEST=ON) on a platform that does not have strndup.

Additional Logs, screenshots, source code, configuration dump, ...

There are two usages of strndup which is specified by POSIX, but not C standard, and thus not widely available, e.g. on Mac OS X 10.5 with gcc 7. On this platform, #2508 is also necessary for cstest.

@Rot127
Copy link
Collaborator

Rot127 commented Oct 17, 2024

Note please, people who find this one and need to test, please use cstest_py.
The C and Python code consume the exact same test cases.

pip install ./bindings/python
pip install ./bindings/python/cstest_py
cstest_py tests/

Note, cstest is not deprecated. I just didn't yet implemented it for other platforms then Linux yet, because if time constraints.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants
@thestr4ng3r @Rot127 and others