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

Update fuzz target source file path and binary name of librawspeed.yaml #752

Merged
merged 1 commit into from
Dec 13, 2024

Conversation

DonggeLiu
Copy link
Collaborator

@DonggeLiu DonggeLiu commented Dec 13, 2024

This is another strange case:

  1. The project is compatible with FI.
  2. FI API did not report any pair.
  3. The trick from Fix fuzz target source path and binary name in gnutls.yaml #750 works:
#!/usr/bin/env bash

# First, find all matching files
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' {} \;)

# For each file, insert a build_id line at the top of the file
for file in $FILES; do
    # Escape any slashes so the file path can be safely inserted by sed
    file_escaped=$(echo "$file" | sed 's/\//\\\//g')

    # Insert the build_id line at the top of the file
    # Adjust the insertion point as needed (e.g., after includes) if desired
    sed -i "1i const volatile char* build_id = \"$file_escaped\";" "$file"
done

echo "build_id line inserted in all matched files."

@DonggeLiu
Copy link
Collaborator Author

/gcbrun skip

@DavidKorczynski DavidKorczynski merged commit d71ae42 into main Dec 13, 2024
5 checks passed
@DavidKorczynski DavidKorczynski deleted the DonggeLiu-patch-1 branch December 13, 2024 09:26
DavidKorczynski pushed a commit that referenced this pull request Dec 17, 2024
`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

```
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

Successfully merging this pull request may close these issues.

2 participants