google / oss-fuzz-gen

LLM powered fuzzing via OSS-Fuzz.
Apache License 2.0
780 stars 92 forks source link

Add instruction for a C++ fuzz target includes a C file from a C++ project #420

Open DonggeLiu opened 2 weeks ago

DonggeLiu commented 2 weeks ago

Example:

In file included from /src/libvpx/examples/vpx_dec_fuzzer.cc:28:
/src/libvpx/vp9/decoder/vp9_decodeframe.c:69:11: error: cannot initialize a variable of type 'TX_MODE' with an rvalue of type 'int'
   69 |   TX_MODE tx_mode = vpx_read_literal(r, 2);

In the long term, we probably should not be required to include source code files.

DonggeLiu commented 2 weeks ago

/gcbrun exp -n dg

DonggeLiu commented 2 weeks ago

/gcbrun exp -f -n dg

DonggeLiu commented 2 weeks ago

@oliverchang @jonathanmetzman Do you happen to know if there is a solution to this error? This error is caused by including a C file in the C++ fuzz target. C allows type casting, but C++ does not, hence the error happened on the #include statement. The original fuzz target is in C++ and so is the project-under-test (openssl). But that specific file vp9_decodeframe.c is in C:

In file included from /src/libvpx/examples/vpx_dec_fuzzer.cc:28:
/src/libvpx/vp9/decoder/vp9_decodeframe.c:69:11: error: cannot initialize a variable of type 'TX_MODE' with an rvalue of type 'int'
   69 |   TX_MODE tx_mode = vpx_read_literal(r, 2);

I tried adding extern "C" around the #include statement, but it does fix the error:

extern "C" {
    #include "/src/libvpx/vp9/decoder/vp9_decodeframe.c"
}