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

#include <string> in fuzztest.h not found #657

Open
marvi3 opened this issue Oct 23, 2023 · 7 comments
Open

#include <string> in fuzztest.h not found #657

marvi3 opened this issue Oct 23, 2023 · 7 comments

Comments

@marvi3
Copy link

marvi3 commented Oct 23, 2023

Hello,

I am sorry, but I am running into a problem when building a project with cmake and fuzztest.
My project is a make c project but I have changed it to a simple cmake project using the provided guide about cmake projects.
I basically have a *.c and a *.h file and would like to build them with fuzztest.

CMakeLists.txt

cmake_minimum_required(VERSION 3.19)
project(fuzztest)

set(CMAKE_CXX_STANDARD 17)

add_subdirectory(fuzztest)

enable_testing()

include(GoogleTest)

fuzztest_setup_fuzzing_flags()

add_compile_definitions(-DMJS_MAIN -DMJS_EXPOSE_PRIVATE -DCS_ENABLE_STDIO -DMJS_ENABLE_DEBUG -DCS_MMAP -DMJS_MODULE_LINES)

add_executable(
  mjs_fuzztest
  mjs_fuzz/mjs.c
  mjs_fuzz/mjs.h
)

link_fuzztest(mjs_fuzztest)
gtest_discover_tests(mjs_fuzztest)

However when I run cmake --build . as described I get the following error:

[ 40%] Building C object CMakeFiles/mjs_fuzztest.dir/mjs.c.o
In file included from src/mjs_main.c:13:
/home/kali/SUT/mjsFuzzTest/fuzztest/fuzztest/fuzztest.h:18:10: fatal error: 'string' file not found
#include <string>

However when I run the example from the cmake file, the first_fuzz_test.cc, everything works like a charme.

How is it possible, that clang can not find the string header?

I hope to get some suggestion, what I might be doing wrong.

@markus-kusano
Copy link
Collaborator

markus-kusano commented Oct 23, 2023 via email

@marvi3
Copy link
Author

marvi3 commented Oct 23, 2023

Hello Markus,
thanks for the quick reply. That is utterly stupid of me. I did not even think about c not having strings and was just all the time wondering what was going on and what I did wrong.

I run the following commands:

CC=clang-16 CXX=clang++-16 cmake -DCMAKE_BUILD_TYPE=RelWithDebug -DFUZZTEST_FUZZING_MODE=on ..
cmake --build .

Does that mean I can not test c programms with fuzztest out of the box?

Best wishes,
marvi3

@markus-kusano
Copy link
Collaborator

markus-kusano commented Oct 23, 2023 via email

@fniksic
Copy link
Collaborator

fniksic commented Oct 27, 2023

As Markus suggested, put your fuzz tests in a C++ file. Include your C header file with C language linkage:

extern "C" {
#include "my/c/header.h"
}

// Call your C functions from fuzz tests.

Then you should be good!

@marvi3
Copy link
Author

marvi3 commented Nov 7, 2023

Thank you a lot for your reply and help.
I have tried to get it working with what you have provided but I am still failing.
I have tried both, to include my c program with the extern keyword and just changing the *.c to a *.cc ending and then adding the cpp code of fuzztest. However I had no success with this.

By the way I think I forgot to tell which SUT I want to build with FuzzTest:
It is mjs, a javascript interpreter.

I am getting a lot of error code that I do not get when building the program originally. Some errors seem to be connected with makros that try to get expanded:

./mjs.c:1650:3: error: expected identifier
LL_NONE = -1,
^
/usr/include/elf.h:2056:20: note: expanded from macro 'LL_NONE'
#define LL_NONE           0
                          ^
In file included from /home/kali/SUT/mjsFuzzTest/mjs_fuzz/fuzztest.cc:4:
./mjs.c:3847:19: error: cannot initialize a variable of type 'enum cs_log_level' with an rvalue of type 'int'
enum cs_log_level cs_log_cur_msg_level WEAK = LL_NONE;

But even when I have fixed them I get this error that I can't seem to fix without breaking other things:

In file included from /home/kali/SUT/mjsFuzzTest/mjs_fuzz/fuzztest.cc:1:
In file included from /home/kali/SUT/mjsFuzzTest/fuzztest/fuzztest/fuzztest.h:23:
In file included from /home/kali/SUT/mjsFuzzTest/fuzztest/./fuzztest/domain.h:18:
In file included from /home/kali/SUT/mjsFuzzTest/fuzztest/./fuzztest/domain_core.h:47:
/home/kali/SUT/mjsFuzzTest/fuzztest/./fuzztest/internal/domains/arbitrary_impl.h:63:3: error: static assertion failed
due to requirement 'foobar<char *>::value': => Type not supported yet. Consider filing an issue.
static_assert(foobar<T>::value,
^             ~~~~~~~~~~~~~~~~ 

This assertion fail also does not happen when I build the program on it's own.

@marvi3
Copy link
Author

marvi3 commented Nov 10, 2023

When I fix all other problems I am left with an error:

fuzztest/./fuzztest/internal/domains/arbitrary_impl.h:63:3: error: static assertion failed due to requirement 'foobar<char *>::value': => Type not supported yet. Consider filing an issue.
  static_assert(foobar<T>::value,

So I simply commented this assertion out and then it throws the following error. So it seems like there is a problem with the value_type. I looked a bit in issues and found issue #176 where it is talked about no longer explicitly defining value_type and the change removed the value_type from InRegexImpl::DomainBase.
Could the problem I am facing be related to this ?

fuzztest/./fuzztest/internal/type_support.h:42:1: error: no type named 'value_type' in 'fuzztest::internal::ArbitraryImpl<char *>'                                                                            using value_type_t = typename Domain::value_type;

I am sorry to bother you guys with my problems but I really do not know how to continue anymore.

@fniksic
Copy link
Collaborator

fniksic commented Nov 10, 2023

Looks like you're trying to instantiate fuzztest::Arbitrary<T>() with a type T that's not supported (which is what the static assert says).

Can you paste the fuzz test somewhere and share a link?

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

No branches or pull requests

3 participants