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

AFL fuzzing #91

Merged
merged 17 commits into from
Nov 1, 2021
Merged

AFL fuzzing #91

merged 17 commits into from
Nov 1, 2021

Conversation

jayantk
Copy link
Contributor

@jayantk jayantk commented Oct 13, 2021

I thought a little bit about how we can avoid some of the issues with the previous approach, and here's a possible solution. The idea is that we make a single fuzzing program that dispatches to different property-based tests based on its command line arguments. We can then declare test cases using JSON by specifying the command line argument + stdin. It's not a perfect solution -- there's still some C++ boilerplate and such -- but it seems like a good effort/reward tradeoff.

This code isn't the cleanest, but hopefully the idea is clear. If you like the idea, I'll clean it up. I also haven't addressed any of the comments on the previous PR yet.

CMakeLists.txt Outdated
# fuzzing applications
#

add_executable( add fuzz/add.cpp )
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(we can rename add.cpp to fuzz or something)

@@ -0,0 +1,4 @@
1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should delete this and have a test runner that reads the JSON files and generates the necessary directories / input files.

@tony-ricciardi
Copy link
Contributor

Previous PR for reference: #88

@jayantk jayantk changed the title (possibly) better way to do afl fuzzing AFL fuzzing Oct 14, 2021
@@ -0,0 +1,4 @@
1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(we should delete this long term, but i left it around so there's an example of how to run afl)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we can settle on an input file format after more usage and examples, but this looks fine for now.

CMakeLists.txt Outdated
@@ -15,7 +15,7 @@ set( CMAKE_INCLUDE_CURRENT_DIR ON )
include_directories( program/src/ )

# gcc compiler/linker flags
add_compile_options( -ggdb -Wall -Wextra -Werror -m64 )
add_compile_options( -ggdb -Wall -Wextra -Werror -Wno-unused-function -m64 )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this for? If actually needed, it would be preferable to mark these functions with [[maybe_unused]], etc., rather than disabling the warning globally.

{
pd_t r[1];
pd_sub( r, n1, n2, p );
return r->v_ > 0L;
}

static void pd_sqrt( pd_t *r, pd_t *val, const int64_t *f )
[[maybe_unused]] static void pd_sqrt( pd_t *r, pd_t *val, const int64_t *f )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should fix these either by marking them as inline or moving the function definitions to a pd.c file. I'll make that change separately though; this is fine for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #94

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Holding off on PR #94 for now. This build failure can be addressed with #97 in the meantime.

README.md Outdated
You can run these tests using a command like:

```
docker run -t --platform linux/amd64 -v "$(pwd)"/findings:/home/pyth/pyth-client/findings pyth-fuzz sh -c "./afl/afl-fuzz -i ./pyth-client/pyth/tests/fuzz/add/testcases -o ./pyth-client/findings ./pyth-client/build/fuzz add"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might look cleaner to break this into multiple lines, e.g.,

docker run -t \
  --platform linux/amd64 \
  -v "$(pwd)"/findings:/home/pyth/pyth-client/findings \
  pyth-fuzz sh -c \
    "./afl/afl-fuzz" \
    "-i ./pyth-client/pyth/tests/fuzz/add/testcases" \
    "-o ./pyth-client/findings" \
    "./pyth-client/build/fuzz add"


```
docker run -t --platform linux/amd64 -v "$(pwd)"/findings:/home/pyth/pyth-client/findings pyth-fuzz sh -c "./pyth-client/build/fuzz add < ./pyth-client/findings/crashes/id\:000000\,sig\:06\,src\:000000\,op\:flip1\,pos\:0"
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multi-line here as well.

@@ -0,0 +1,4 @@
1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we can settle on an input file format after more usage and examples, but this looks fine for now.

@tony-ricciardi tony-ricciardi marked this pull request as draft October 15, 2021 17:18
@tony-ricciardi tony-ricciardi marked this pull request as ready for review October 15, 2021 17:18
Copy link
Contributor

@tony-ricciardi tony-ricciardi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tony-ricciardi pushed a commit to tony-ricciardi/pyth-client that referenced this pull request Oct 15, 2021
- Avoid duplicating definitions across compilation units.
- Allow including `pd.h` in test sources without adding -Wno-unused-function (pyth-network#91).
tony-ricciardi pushed a commit to tony-ricciardi/pyth-client that referenced this pull request Oct 18, 2021
- Allows including `pd.h` in test sources without adding `-Wno-unused-function`. See pyth-network#91
@tony-ricciardi tony-ricciardi added the testing New tests or test/CI infrastructure label Oct 18, 2021
@tony-ricciardi tony-ricciardi linked an issue Oct 18, 2021 that may be closed by this pull request
@tony-ricciardi
Copy link
Contributor

tony-ricciardi commented Oct 18, 2021

Tracking related changes with Issue #99.

@tony-ricciardi tony-ricciardi mentioned this pull request Oct 18, 2021
tony-ricciardi pushed a commit to tony-ricciardi/pyth-client that referenced this pull request Oct 18, 2021
- Allows including `pd.h` in test sources without adding `-Wno-unused-function`.
  - See pyth-network#91

std::cout.precision(12);

if (strcmp(argv[1], "add") == 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a better way to do this?

@tony-ricciardi tony-ricciardi merged commit e917031 into main Nov 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing New tests or test/CI infrastructure
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fuzz Testing
2 participants