Skip to content

Commit

Permalink
Update fuzz target source file path and binary name (#753)
Browse files Browse the repository at this point in the history
`nss` failed FI build, found the new pair by improving the script in
#752:

```bash
#!/usr/bin/env bash

PREFIX="OFG_UNIQUE_PREFIX_"

# Find all source files containing 'LLVMFuzzerTestOneInput' and exclude specific paths
FILES=$(find /src \
    -type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.cxx' \) \
    -not -path '*/aflplusplus/*' \
    -not -path '*/fuzztest/*' \
    -not -path '*/honggfuzz/*' \
    -not -path '*/libfuzzer/*' \
    -exec grep -l 'LLVMFuzzerTestOneInput' {} \;)

count=1
for file in $FILES; do
    echo "Inserting into $file"

    # Detect whether the file is C or C++ based on its extension
    if [[ "$file" == *.c ]]; then
        # Code for C files
        if ! grep -q "build_id_$count" "$file"; then
            cat <<EOF >>"$file"

#include <stdio.h>

const char build_id_$count[] __attribute__((used)) = "$PREFIX$file";

__attribute__((constructor))
static void reference_build_id_$count(void) {
    fprintf(stderr, "%s\\n", build_id_$count);
}

EOF
        fi
    else
        # Code for C++ files
        if ! grep -q "struct OFGBuildIdReference" "$file"; then
            cat <<EOF >>"$file"

#include <cstdio>

const char build_id_$count[] __attribute__((used)) = "$PREFIX$file";

struct OFGBuildIdReference {
    ~OFGBuildIdReference() {
        fprintf(stderr, "%s\\n", build_id_$count);
    }
};

static OFGBuildIdReference ref;

EOF
        fi
    fi

    count=$((count+1))
done

echo "Unique build_id lines inserted in all matched files."

```

```bash
#!/usr/bin/env bash
PREFIX="OFG_UNIQUE_PREFIX_"

for bin in /out/*; do
    [ -f "$bin" -a -x "$bin" ] || continue
    binary_name=$(basename "$bin")

    # Extract lines containing PREFIX, remove prefix, then check each filepath
    while IFS= read -r filepath; do
        [ -z "$filepath" ] && continue
        if [ -f "$filepath" ]; then
            export TARGET_NAME="$binary_name" TARGET_PATH="$filepath"
            echo "Binary: $TARGET_NAME"
            echo "Source file: $TARGET_PATH"
            echo
        else
            echo "Binary: $binary_name"
            echo "Source file (not found): $filepath"
            echo
        fi
    done < <(strings "$bin" | grep "$PREFIX" | sed "s/^$PREFIX//")
done

```
  • Loading branch information
DonggeLiu authored Dec 17, 2024
1 parent 8e81df6 commit 64d7504
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions benchmark-sets/all/neomutt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@
"signature": "int mutt_send_message(SendFlags, struct Email *, const char *, struct Mailbox *, struct EmailArray *, struct ConfigSubset *)"
"language": "c++"
"project": "neomutt"
"target_name": "fuzz/date.c"
"target_path": "/src/neomutt/fuzz/date.c"
"target_name": "address-fuzz"
"target_path": "/src/neomutt/fuzz/address.c"
4 changes: 2 additions & 2 deletions benchmark-sets/all/nss.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,5 @@
"signature": "CK_RV s_open(const char *, const char *, const char *, int, int, int, SDB **, SDB **, int *)"
"language": "c++"
"project": "nss"
"target_name": "mpi-mod"
"target_path": "/src/nss/fuzz/mpi_mod_target.cc"
"target_name": "certDN"
"target_path": "OFG_UNIQUE_PREFIX_/src/nss/fuzz/targets/certDN.cc"
2 changes: 1 addition & 1 deletion benchmark-sets/all/perfetto.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@
"signature": "vector<unsigned char, std::__1::allocator<unsigned char> > perfetto::protos::gen::Trace::SerializeAsArray()"
"language": "c++"
"project": "perfetto"
"target_name": "/work/build/../../src/perfetto/src/profiling/memory/shared_ring_buffer_write_fuzzer.cc"
"target_name": "shared_ring_buffer_write_fuzzer"
"target_path": "/src/perfetto/src/profiling/memory/shared_ring_buffer_write_fuzzer.cc"
2 changes: 1 addition & 1 deletion benchmark-sets/all/tinyusb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@
"signature": "struct tcp_pcb * tcp_listen_with_backlog(struct tcp_pcb *, u8_t)"
"language": "c++"
"project": "tinyusb"
"target_name": "/src/tinyusb/test/fuzz/device/cdc/src/fuzz.cc"
"target_name": "cdc"
"target_path": "/src/tinyusb/test/fuzz/device/cdc/src/fuzz.cc"
4 changes: 2 additions & 2 deletions benchmark-sets/all/wpantund.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@
"signature": "int nl::wpantund::SpinelNCPTaskScan::vprocess_event(int, struct __va_list_tag *)"
"language": "c++"
"project": "wpantund"
"target_name": "ncp-spinel-fuzz"
"target_path": "/src/wpantund/src/ncp-spinel/ncp-spinel-fuzz.cpp"
"target_name": "wpantund-fuzz"
"target_path": "/src/wpantund/src/wpantund/wpantund-fuzz.cpp"
2 changes: 1 addition & 1 deletion benchmark-sets/all/wuffs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
"language": "c++"
"project": "wuffs"
"target_name": "bzip2_fuzzer"
"target_path": "/src/wuffs/fuzz/c/fuzzlib/fuzzlib.c"
"target_path": "/src/wuffs/fuzz/c/std/bzip2_fuzzer.c"
2 changes: 1 addition & 1 deletion benchmark-sets/all/yoga.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
"signature": "bool facebook::yoga::Style::operator!=(const Style &)"
"language": "c++"
"project": "yoga"
"target_name": "/src/yoga/fuzz/FuzzLayout.cpp"
"target_name": "fuzz_layout"
"target_path": "/src/yoga/fuzz/FuzzLayout.cpp"

0 comments on commit 64d7504

Please sign in to comment.