-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test: setup fuzzing * style: fmt * style: reorder workspace members * chore: set fuzz package name to logos-fuzz * docs: fuzzing * chore: make fuzzer private * docs: mention fuzzing definition Co-authored-by: Jérome Eertmans <[email protected]> * docs(book): style logos to be bold Co-authored-by: Jérome Eertmans <[email protected]> * docs(book/fuzzing): style, more notes about subcommands, reporting info. Co-authored-by: Jérome Eertmans <[email protected]> * chore: fix fuzz crate metadata * chore(msrv): bump to 1.70.0 * fix: msrv should also be duplicated --------- Co-authored-by: Jérome Eertmans <[email protected]>
- Loading branch information
Showing
11 changed files
with
109 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,6 @@ | |
/book/book | ||
**/*.rs.bk | ||
Cargo.lock | ||
|
||
# ignore output fuzzing | ||
out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Fuzzing | ||
|
||
|
||
Fuzzing is a technique to test a piece of software by injecting randomly generated inputs. This can be pretty useful to discover bugs, as pointed out in [#407](https://github.com/maciejhirsz/logos/pull/407). | ||
|
||
**Logos**' fuzzing crate is powered by [afl.rs](https://github.com/rust-fuzz/afl.rs) that | ||
finds panics in **Logos**' methods. | ||
|
||
## Usage | ||
|
||
First, make sure you have `cargo-afl` installed, | ||
[see the rust-fuzz afl setup guide for installation information](https://rust-fuzz.github.io/book/afl/setup.html). | ||
|
||
Next, change your current working directory to be the `fuzz` folder. | ||
|
||
### Building | ||
|
||
Before fuzzing, you need to build the target with: | ||
|
||
```bash | ||
cargo afl build | ||
``` | ||
|
||
### Fuzzy testing | ||
|
||
The recommended way the run tests is with: | ||
|
||
```bash | ||
cargo afl fuzz -i in -o out ../target/debug/logos-fuzz | ||
``` | ||
|
||
Note that it may run for a (very) long time before | ||
it encounter any bug. | ||
|
||
## Replaying a Crash | ||
|
||
If you happen to find a bug that crashes the program, | ||
you can reply it with | ||
|
||
```bash | ||
cargo afl run logos-fuzz < out/default/crashes/crash_file | ||
``` | ||
|
||
### Reporting a Bug | ||
|
||
If you encounter a crash and you feel the error message | ||
is not appropriate, | ||
please report it by opening | ||
[an issue](https://github.com/maciejhirsz/logos/issues/new). | ||
Don't forget to include your crash file so we can later | ||
reproduce it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[package] | ||
name = "logos-fuzz" | ||
authors.workspace = true | ||
categories.workspace = true | ||
description.workspace = true | ||
edition.workspace = true | ||
homepage.workspace = true | ||
keywords.workspace = true | ||
license.workspace = true | ||
readme.workspace = true | ||
repository.workspace = true | ||
rust-version.workspace = true | ||
version.workspace = true | ||
publish = false | ||
|
||
[dependencies] | ||
afl = "0.15" | ||
arbitrary = "1.3" | ||
logos-codegen = { path = "../logos-codegen", features = ["fuzzing"] } | ||
|
||
[package.metadata.release] | ||
shared-version = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
literal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
a+b[cd-h]+? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use afl::fuzz; | ||
use logos_codegen::{ | ||
graph::{Graph, Node}, | ||
mir::Mir, | ||
}; | ||
|
||
fn main() { | ||
fuzz!(|regex: String| { | ||
let mut graph = Graph::new(); | ||
|
||
if let Ok(mir) = Mir::utf8(®ex) { | ||
let leaf = graph.push(Node::Leaf("LEAF")); | ||
let _ = graph.regex(mir, leaf); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters