Browse Source

add fuzzer test program to fuzz libpEpMIME and libetpan

afl-fuzzing
Roker 3 years ago
parent
commit
f4ea957bee
3 changed files with 106 additions and 1 deletions
  1. +7
    -1
      src/Makefile
  2. +72
    -0
      src/fuzz.cc
  3. +27
    -0
      src/unittest_mime.cc

+ 7
- 1
src/Makefile View File

@ -7,7 +7,7 @@ GTEST_DIR=$(HOME)/code/googletest/
-include local.conf
all: libpEpMIME.a unittests
all: libpEpMIME.a unittests fuzz
libpEpMIME.a: pEpMIME.o pEpMIME_internal.o rules.o bodyparser.o \
headerparser.o parse_timestamp.o parse_address.o nulllogger.o \
@ -29,6 +29,12 @@ gtest_main.o: $(GTEST_DIR)/src/gtest_main.cc
unittest_%.o : unittest_%.cc
${CXX} -I${HOME}/local/include/ -I/usr/local/include -isystem $(GTEST_DIR)/include -o $@ -c $<
fuzz: fuzz.o libpEpMIME.a
${CXX} -L${HOME}/local/lib/ -o $@ $^ -lpEpAdapter -lpEpEngine -lpthread -liconv
fuzz.o: fuzz.cc
${CXX} -I${HOME}/local/include/ -o $@ -c $^
%.o : %.cc %.hh
${CXX} -I${HOME}/local/include/ -I/usr/local/include -o $@ -c $<


+ 72
- 0
src/fuzz.cc View File

@ -0,0 +1,72 @@
// test program to "fuzz" libpEpMIME (and libetpan for comparison)
#include "pEpMIME.hh"
#include <pEp/mime.h>
#include <cstdio>
#include <iostream>
#include <fstream>
#include <sstream>
void printhelpmessage(std::ostream& o)
{
o << "Usage: fuzz {-p|-e} <example.eml> […]\n\n"
"\t-p : use libpEpMIME as MIME parser\n"
"\t-e : use libetpan as MIME parser\n"
"\n";
}
std::string slurp(const std::string& filename)
{
std::ifstream input(filename.c_str(), std::ios_base::binary);
if(!input)
{
throw std::runtime_error("Cannot read file \"" + filename + "\"! ");
}
std::stringstream sstr;
sstr << input.rdbuf();
return sstr.str();
}
int main(int argc, char** argv)
{
if(argc==1)
{
printhelpmessage(std::cerr);
return 1;
}
const std::string argv1 = argv[1];
if(argv1 == "-p")
{
// test with libpEpMIME
for(int a=2; a<argc; ++a)
{
const std::string f = slurp(argv[a]);
message* m = pEpMIME::parse_message(f.c_str(), f.size());
free_message(m);
}
return 0;
}else if(argv1 == "-e")
{
// test with libetpan
for(int a=2; a<argc; ++a)
{
const std::string f = slurp(argv[a]);
message* m = nullptr;
auto status = mime_decode_message(f.c_str(), f.size(), &m);
std::cerr << "Status: " << status << "\n";
free_message(m);
}
return 0;
}else if(argv1 == "-h" || argv1=="--help")
{
printhelpmessage(std::cout);
return 0;
}
printhelpmessage(std::cerr);
return 1;
}

+ 27
- 0
src/unittest_mime.cc View File

@ -72,6 +72,33 @@ namespace {
"R=C3=B8dgr=C3=B8d med fl=C3=B8de?\r\n"
"\r\n"
"\r\n"
"--==pEp_02==\r\n"
"Content-Type: application/octet-stream; name=\"This is a long\r\n"
" file name so it is split to multiple\r\n"
" physical lines.bin\"\r\n"
"Content-Language: en-US\r\n"
"Content-Transfer-Encoding: base64\r\n"
"Content-Disposition: attachment;\r\n"
" filename*0=\"This is a long file name so it is split to\";\r\n"
" filename*1=\" multiple physical lines.bin\";\r\n"
"\r\n"
"w5xiZXJncsO2w59lbsOkbmRlcnVuZyEK\r\n"
"\r\n"
"--==pEp_02==\r\n"
"Content-Type: application/octet-stream; name=\"=?UTF-8?B?8J+SqSDwn5iAIPCf?="
" =?UTF-8?B?kqkg8J+YgCDwn5KpIPCfmIAg8J+SqSDwn5iAIPCfkqkg8J+YgCDwn5KpIPCfm?="
" =?UTF-8?B?IAg8J+SqSDwn5iAIPCfkqkg8J+YgC5wbmc=?=\r\n"
"Content-Language: en-US\r\n"
"Content-Transfer-Encoding: base64\r\n"
"Content-Disposition: attachment;\r\n"
" filename*0*=utf-8''%F0%9F%92%A9%20%F0%9F%98%80%20%F0%9F%92%A9%20%F0;\r\n"
" filename*1*=%9F%98%80%20%F0%9F%92%A9%20%F0%9F%98%80%20%F0%9F%92%A9;\r\n"
" filename*2*=%20%F0%9F%98%80%20%F0%9F%92%A9%20%F0%9F%98%80%20%F0%9F;\r\n"
" filename*3*=%92%A9%20%F0%9F%98%80%20%F0%9F%92%A9%20%F0%9F%98%80%20;\r\n"
" filename*4*=%F0%9F%92%A9%20%F0%9F%98%80.png\r\n"
"\r\n"
"w5xiZXJncsO2w59lbsOkbmRlcnVuZyEK\r\n"
"\r\n"
"--==pEp_02==--\r\n"
"\r\n"
"--==pEp_01==\r\n"


Loading…
Cancel
Save