Skip to content

Commit

Permalink
fix bugs && prepare 50 cases with headerfiles (#643)
Browse files Browse the repository at this point in the history
**Statement**: Most modifications to the original code of `oss-fuzz-gen`
(including items 2. and 3. below) are for the convenience of current
testing and performance comparison based on Gemini. The current changes
will not be the final merge changes.

Modifications to be noted:

1. Changed c projects like **picotls**, **libvnc**'s language setting in
yaml from c++ to c. Otherwise, the prompt will provide an example of
c++, and the large model imitation the c++ example to include
FuzzydDataProvider. h (c++).

2. Added `headerfiles `project as a module in the oss-fuzz-gen project.
Therefore, the include statement changed from _import headerfiles.api as
headerfiles_ to _from headerfiles.headerfiles import api as
headerfiles_. (This facilitates us to adjust the code in the
`headerfiles` at any time, and eventually, we will package it as an
external library)

3. Changed the function:
https://github.com/occia/oss-fuzz-gen/blob/e71091bab8b4ac20a2e575ee9f7cbce91a987fdd/data_prep/project_src.py#L238
to avoid the bug: "docker: Error response from daemon: Conflict."

4. Project **bind9**: Execute _make "-j\$(nproc)"_ in original build.sh
sometimes cause link errors, related to the setting of multithreading in
the project. Execute _make_ produce no errors (by
headersfile_updated_script).

5. Project **openexr**: The header files introduced by `headerfiles`
will be part of the prompt, occasionally affecting the generation of
LLM. Haven't found a solution yet.
_"We have prepared the following list of headers which covers all target project APIs and will prepend them as #include statments at the beginning of your generated fuzz target. Therefore, you only need to include the headers of non-target-project APIs used in your fuzz target.
\<code\> dns/acl.h..."_.



Overall Results:
(Based on GPT-4o)
PROJ | ORI | FIX
-- | -- | --
avahi | 16 | 18
bind9 | 21 | 14
bluez | 0 | 0
brotli | 0 | 1
capstone | 35 | 50
coturn | 16 | 18
croaring | 42 | 50
igraph | 0 | 0
kamailio | 6 | 28
krb5 | 0 | 0
lcms | 0 | 37
libbpf | 0 | 39
libcoap | 0 | 0
libevent | 4 | 28
libfido2 | 0 | 50
libical | 6 | 16
libjpeg-turbo | 39 | 50
libpcap | 50 | 50
librdkafka | 0 | 0
libsndfile | 39 | 45
libsodium | 0 | 0
libssh2 | 26 | 25
libssh | 22 | 32
libtpms | 40 | 40
libusb | 1 | 27
libvnc | 0 | 24
libxls | 0 | 33
libyang | 1 | 0
lwan | 0 | 8
mbedtls | 0 | 16
mdbtools | 0 | 0
minizip | 50 | 50
ndpi | 1 | 7
njs | 2 | 0
oniguruma | 20 | 20
openexr | 17 | 0
opusfile | 23 | 36
picotls | 43 | 41
pjsip | 14 | 19
proftpd | 23 | 44
pupnp | 29 | 29
sleuthkit | 0 | 0
tidy-html5 | 35 | 39
unicorn | 0 | 0
unit | 15 | 13
utf8proc | 20 | 20
vlc | 6 | 9
w3m | 34 | 30
wasm3 | 5 | 15
zydis | 0 | 0

---------

Co-authored-by: Cen Zhang <[email protected]>
  • Loading branch information
Once2gain and occia authored Sep 23, 2024
1 parent ba0f78d commit b36f237
Show file tree
Hide file tree
Showing 73 changed files with 5,822 additions and 11 deletions.
9 changes: 9 additions & 0 deletions benchmark-sets/headerfiles/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Selected 50 projects to test the effectiveness of headerfiles. It should be noted that we have corrected the language settings of the following projects:

**From c++ to c:**
avahi.yaml, brotli.yaml, capstone.yaml, lcms.yaml, libcoap.yaml, libfido2.yaml, libpcap.yaml, librdkafka.yaml, libtpms.yaml, libvnc.yaml, libxls.yaml, mbedtls.yaml, minizip.yaml, ndpi.yaml, njs.yaml, picotls.yaml, tidy-html5.yaml, unicorn.yaml

(In case of incorrect settings, prompt will provide a c++ fuzz target example, and LLM will mimic it by including "FuzzydDataProvider.h", causing compilation errors.)

**From c to c++:**
libjpeg-turbo.yaml, libsndfile.yaml
56 changes: 56 additions & 0 deletions benchmark-sets/headerfiles/avahi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"functions":
- "exceptions": []
"name": "avahi_string_list_new"
"params":
- "name": "txt"
"type": "bool "
"return_type": "void"
"signature": "AvahiStringList * avahi_string_list_new(const char *, void)"
- "exceptions": []
"name": "avahi_string_list_add_vprintf"
"params":
- "name": "l"
"type": "bool "
- "name": "format"
"type": "bool "
- "name": "va"
"type": "bool "
"return_type": "void"
"signature": "AvahiStringList * avahi_string_list_add_vprintf(AvahiStringList *, const char *, struct __va_list_tag *)"
- "exceptions": []
"name": "avahi_string_list_add_printf"
"params":
- "name": "l"
"type": "bool "
- "name": "format"
"type": "bool "
"return_type": "void"
"signature": "AvahiStringList * avahi_string_list_add_printf(AvahiStringList *, const char *, void)"
- "exceptions": []
"name": "avahi_dns_packet_new_reply"
"params":
- "name": "p"
"type": "bool "
- "name": "mtu"
"type": "int"
- "name": "copy_queries"
"type": "int"
- "name": "aa"
"type": "int"
"return_type": "void"
"signature": "AvahiDnsPacket * avahi_dns_packet_new_reply(AvahiDnsPacket *, unsigned int, int, int)"
- "exceptions": []
"name": "avahi_string_list_add_pair"
"params":
- "name": "l"
"type": "bool "
- "name": "key"
"type": "bool "
- "name": "value"
"type": "bool "
"return_type": "void"
"signature": "AvahiStringList * avahi_string_list_add_pair(AvahiStringList *, const char *, const char *)"
"language": "c"
"project": "avahi"
"target_name": "fuzz-packet"
"target_path": "/src/avahi/fuzz/fuzz-packet.c"
70 changes: 70 additions & 0 deletions benchmark-sets/headerfiles/bind9.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"functions":
- "exceptions": []
"name": "dns_view_freezezones"
"params":
- "name": "view"
"type": "bool "
- "name": "value"
"type": "bool"
"return_type": "int"
"signature": "isc_result_t dns_view_freezezones(dns_view_t *, bool)"
- "exceptions": []
"name": "dns_view_asyncload"
"params":
- "name": "view"
"type": "bool "
- "name": "newonly"
"type": "bool"
- "name": "callback"
"type": "bool "
- "name": "arg"
"type": "bool "
"return_type": "int"
"signature": "isc_result_t dns_view_asyncload(dns_view_t *, bool, dns_zt_callback_t *, void *)"
- "exceptions": []
"name": "dns_zt_asyncload"
"params":
- "name": "zt"
"type": "bool "
- "name": "newonly"
"type": "bool"
- "name": "loaddone"
"type": "bool "
- "name": "arg"
"type": "bool "
"return_type": "int"
"signature": "isc_result_t dns_zt_asyncload(dns_zt_t *, bool, dns_zt_callback_t *, void *)"
- "exceptions": []
"name": "dns_zt_freezezones"
"params":
- "name": "zt"
"type": "bool "
- "name": "view"
"type": "bool "
- "name": "freeze"
"type": "bool"
"return_type": "int"
"signature": "isc_result_t dns_zt_freezezones(dns_zt_t *, dns_view_t *, bool)"
- "exceptions": []
"name": "dns__rbtdb_addrdataset"
"params":
- "name": "db"
"type": "bool "
- "name": "node"
"type": "bool "
- "name": "version"
"type": "bool "
- "name": "now"
"type": "int"
- "name": "rdataset"
"type": "bool "
- "name": "options"
"type": "int"
- "name": "addedrdataset"
"type": "bool "
"return_type": "int"
"signature": "isc_result_t dns__rbtdb_addrdataset(dns_db_t *, dns_dbnode_t *, dns_dbversion_t *, isc_stdtime_t, dns_rdataset_t *, unsigned int, dns_rdataset_t *)"
"language": "c"
"project": "bind9"
"target_name": "dns_qpkey_name_fuzzer"
"target_path": "/src/bind9/fuzz/dns_qpkey_name.c"
86 changes: 86 additions & 0 deletions benchmark-sets/headerfiles/bluez.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
"functions":
- "exceptions": []
"name": "g_obex_put_req"
"params":
- "name": "obex"
"type": "bool "
- "name": "data_func"
"type": "bool "
- "name": "complete_func"
"type": "bool "
- "name": "user_data"
"type": "bool "
- "name": "err"
"type": "bool "
- "name": "first_hdr_id"
"type": "int"
"return_type": "int"
"signature": "guint g_obex_put_req(GObex *, GObexDataProducer, GObexFunc, gpointer, GError **, guint, void)"
- "exceptions": []
"name": "g_obex_new"
"params":
- "name": "io"
"type": "bool "
- "name": "transport_type"
"type": "int"
- "name": "io_rx_mtu"
"type": "size_t"
- "name": "io_tx_mtu"
"type": "size_t"
"return_type": "void"
"signature": "GObex * g_obex_new(GIOChannel *, GObexTransportType, gssize, gssize)"
- "exceptions": []
"name": "g_obex_get_req"
"params":
- "name": "obex"
"type": "bool "
- "name": "data_func"
"type": "bool "
- "name": "complete_func"
"type": "bool "
- "name": "user_data"
"type": "bool "
- "name": "err"
"type": "bool "
- "name": "first_hdr_id"
"type": "int"
"return_type": "int"
"signature": "guint g_obex_get_req(GObex *, GObexDataConsumer, GObexFunc, gpointer, GError **, guint, void)"
- "exceptions": []
"name": "g_obex_get_req_pkt"
"params":
- "name": "obex"
"type": "bool "
- "name": "req"
"type": "bool "
- "name": "data_func"
"type": "bool "
- "name": "complete_func"
"type": "bool "
- "name": "user_data"
"type": "bool "
- "name": "err"
"type": "bool "
"return_type": "int"
"signature": "guint g_obex_get_req_pkt(GObex *, GObexPacket *, GObexDataConsumer, GObexFunc, gpointer, GError **)"
- "exceptions": []
"name": "g_obex_put_req_pkt"
"params":
- "name": "obex"
"type": "bool "
- "name": "req"
"type": "bool "
- "name": "data_func"
"type": "bool "
- "name": "complete_func"
"type": "bool "
- "name": "user_data"
"type": "bool "
- "name": "err"
"type": "bool "
"return_type": "int"
"signature": "guint g_obex_put_req_pkt(GObex *, GObexPacket *, GObexDataProducer, GObexFunc, gpointer, GError **)"
"language": "c"
"project": "bluez"
"target_name": "fuzz_sdp"
"target_path": "/src/fuzz_sdp.c"
58 changes: 58 additions & 0 deletions benchmark-sets/headerfiles/brotli.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"functions":
- "exceptions": []
"name": "BrotliDecoderAttachDictionary"
"params":
- "name": ""
"type": "bool "
- "name": ""
"type": "int"
- "name": ""
"type": "size_t"
- "name": ""
"type": "bool "
"return_type": "int"
"signature": "int BrotliDecoderAttachDictionary(BrotliDecoderStateInternal *, BrotliSharedDictionaryType, size_t, const uint8_t *)"
- "exceptions": []
"name": "BrotliDecoderIsFinished"
"params":
- "name": ""
"type": "bool "
"return_type": "int"
"signature": "int BrotliDecoderIsFinished(const BrotliDecoderStateInternal *)"
- "exceptions": []
"name": "BrotliSafeReadBits32Slow"
"params":
- "name": ""
"type": "bool "
- "name": ""
"type": "size_t"
- "name": ""
"type": "bool "
"return_type": "int"
"signature": "int BrotliSafeReadBits32Slow(const BrotliBitReader *, uint64_t, uint64_t *)"
- "exceptions": []
"name": "BrotliDecoderDecompress"
"params":
- "name": ""
"type": "size_t"
- "name": ""
"type": "bool "
- "name": ""
"type": "bool "
- "name": ""
"type": "bool "
"return_type": "int"
"signature": "BrotliDecoderResult BrotliDecoderDecompress(size_t, const uint8_t *, size_t *, uint8_t *)"
- "exceptions": []
"name": "BrotliDecoderTakeOutput"
"params":
- "name": ""
"type": "bool "
- "name": ""
"type": "bool "
"return_type": "void"
"signature": "const uint8_t * BrotliDecoderTakeOutput(BrotliDecoderStateInternal *, size_t *)"
"language": "c"
"project": "brotli"
"target_name": "decode_fuzzer"
"target_path": "/src/brotli/c/fuzz/decode_fuzzer.c"
84 changes: 84 additions & 0 deletions benchmark-sets/headerfiles/capstone.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
"functions":
- "exceptions": []
"name": "BPF_getInstruction"
"params":
- "name": "ud"
"type": "size_t"
- "name": "code"
"type": "bool "
- "name": "code_len"
"type": "size_t"
- "name": "instr"
"type": "bool "
- "name": "size"
"type": "bool "
- "name": "address"
"type": "size_t"
- "name": "info"
"type": "bool "
"return_type": "bool"
"signature": "bool BPF_getInstruction(csh, const uint8_t *, size_t, MCInst *, uint16_t *, uint64_t, void *)"
- "exceptions": []
"name": "LoongArch_printer"
"params":
- "name": "MI"
"type": "bool "
- "name": "O"
"type": "bool "
- "name": "info"
"type": "bool "
"return_type": "void"
"signature": "void LoongArch_printer(MCInst *, SStream *, void *)"
- "exceptions": []
"name": "PPC_getInstruction"
"params":
- "name": "ud"
"type": "size_t"
- "name": "code"
"type": "bool "
- "name": "code_len"
"type": "size_t"
- "name": "instr"
"type": "bool "
- "name": "size"
"type": "bool "
- "name": "address"
"type": "size_t"
- "name": "info"
"type": "bool "
"return_type": "bool"
"signature": "bool PPC_getInstruction(csh, const uint8_t *, size_t, MCInst *, uint16_t *, uint64_t, void *)"
- "exceptions": []
"name": "ARM_getInstruction"
"params":
- "name": "ud"
"type": "size_t"
- "name": "code"
"type": "bool "
- "name": "code_len"
"type": "size_t"
- "name": "instr"
"type": "bool "
- "name": "size"
"type": "bool "
- "name": "address"
"type": "size_t"
- "name": "info"
"type": "bool "
"return_type": "bool"
"signature": "bool ARM_getInstruction(csh, const uint8_t *, size_t, MCInst *, uint16_t *, uint64_t, void *)"
- "exceptions": []
"name": "AArch64_printer"
"params":
- "name": "MI"
"type": "bool "
- "name": "O"
"type": "bool "
- "name": "info"
"type": "bool "
"return_type": "void"
"signature": "void AArch64_printer(MCInst *, SStream *, void *)"
"language": "c"
"project": "capstone"
"target_name": "driverbin"
"target_path": "/src/capstonev5/suite/fuzz/driverbin.c"
Loading

0 comments on commit b36f237

Please sign in to comment.