forked from neomutt/neomutt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
155 additions
and
2 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 |
---|---|---|
|
@@ -11,6 +11,7 @@ docs/makedoc | |
neomutt | ||
pgpewrap | ||
test/neomutt-test | ||
fuzz/address-fuzz | ||
|
||
# Build products | ||
*.o | ||
|
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,24 @@ | ||
FUZZ_OBJS = fuzz/address.o | ||
|
||
CFLAGS += -I$(SRCDIR)/fuzz | ||
|
||
FUZZ_ADDRESS = fuzz/address-fuzz$(EXEEXT) | ||
|
||
.PHONY: fuzz | ||
fuzz: $(FUZZ_ADDRESS) | ||
|
||
$(FUZZ_ADDRESS): $(FUZZ_OBJS) $(NEOMUTTOBJS) $(MUTTLIBS) $(NEOMUTTLIBS) | ||
$(CXX) $(CXXFLAGS) -o $@ $(FUZZ_OBJS) $(NEOMUTTOBJS) $(MUTTLIBS) $(NEOMUTTLIBS) $(LDFLAGS) $(LIBS) $(LIB_FUZZING_ENGINE) | ||
|
||
all-fuzz: $(FUZZ_ADDRESS) | ||
|
||
clean-fuzz: | ||
$(RM) $(FUZZ_ADDRESS) $(FUZZ_OBJS) $(FUZZ_OBJS:.o=.Po) | ||
|
||
install-fuzz: | ||
uninstall-fuzz: | ||
|
||
FUZZ_DEPFILES = $(FUZZ_OBJS:.o=.Po) | ||
-include $(FUZZ_DEPFILES) | ||
|
||
# vim: set ts=8 noexpandtab: |
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,59 @@ | ||
## Fuzzing NeoMutt | ||
|
||
NeoMutt has some support for Fuzzing. | ||
|
||
- https://en.wikipedia.org/wiki/Fuzzing | ||
|
||
It's currently limited to two functions. | ||
Two that could be susceptible to remote attacks. | ||
|
||
- `mutt_rfc822_read_header();` | ||
- `mutt_parse_part();` | ||
|
||
The fuzzing machinery uses a custom entry point to the code. | ||
This can be found in `fuzz/address.c` | ||
|
||
```c | ||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) | ||
``` | ||
### Build the Fuzzer | ||
To build the fuzzer, we need to build with `clang` and pass some extra flags: | ||
```sh | ||
# Set some environment variables | ||
export EXTRA_CFLAGS="-fsanitize=fuzzer" | ||
export CXXFLAGS="$EXTRA_CFLAGS" | ||
``` | ||
|
||
```sh | ||
# Configure and build | ||
./configure CC=clang --disable-doc --quiet --fuzzing | ||
make CC=clang CXX=clang fuzz | ||
``` | ||
|
||
### Run the Fuzzer | ||
|
||
The fuzzer can be run by simply: | ||
|
||
```sh | ||
fuzz/address-fuzz | ||
``` | ||
|
||
or it can be run against our corpus of test cases: | ||
|
||
```sh | ||
# Run the fuzzer on the sample data | ||
git clone https://github.com/neomutt/corpus-address.git | ||
fuzz/address-fuzz corpus-address | ||
``` | ||
|
||
To see some more options, run: | ||
|
||
```sh | ||
fuzz/address-fuzz -help=1 | ||
``` | ||
|
||
Adding the option `-max_total_time=3600` will limit the run time to one hour. | ||
|
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,41 @@ | ||
#include <signal.h> | ||
#include <stdbool.h> | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
#include <sys/stat.h> | ||
#include "mutt/logging.h" | ||
#include "config/set.h" | ||
#include "email/body.h" | ||
#include "email/email.h" | ||
#include "email/envelope.h" | ||
#include "email/mime.h" | ||
#include "email/parse.h" | ||
#include "core/neomutt.h" | ||
#include "init.h" | ||
#include "options.h" | ||
|
||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) | ||
{ | ||
MuttLogger = log_disp_null; | ||
struct ConfigSet *cs = cs_new(16); | ||
NeoMutt = neomutt_new(cs); | ||
init_config(cs); | ||
OptNoCurses = 1; | ||
char file[] = "/tmp/mutt-fuzz"; | ||
FILE *fp = fopen(file, "wb"); | ||
if (fp != NULL) | ||
{ | ||
fwrite(data, 1, size, fp); | ||
fclose(fp); | ||
} | ||
fp = fopen(file, "rb"); | ||
struct Email *e = email_new(); | ||
struct Envelope *env = mutt_rfc822_read_header(fp, e, 0, 0); | ||
mutt_parse_part(fp, e->body); | ||
email_free(&e); | ||
mutt_env_free(&env); | ||
fclose(fp); | ||
neomutt_free(&NeoMutt); | ||
cs_free(&cs); | ||
return 0; | ||
} |
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