-
Notifications
You must be signed in to change notification settings - Fork 188
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
1 parent
5fdba9e
commit 36a36fa
Showing
3 changed files
with
106 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
GET /hoge HTTP/1.1 | ||
Host: example.com | ||
Cookie: | ||
|
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,100 @@ | ||
#if !FD_HAS_HOSTED | ||
#error "This target requires FD_HAS_HOSTED" | ||
#endif | ||
|
||
#include <assert.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
|
||
#include "../../util/fd_util.h" | ||
#include "picohttpparser.h" | ||
|
||
int | ||
LLVMFuzzerInitialize( int * argc, | ||
char *** argv ) { | ||
/* Set up shell without signal handlers */ | ||
putenv( "FD_LOG_BACKTRACE=0" ); | ||
fd_boot( argc, argv ); | ||
atexit( fd_halt ); | ||
|
||
/* Disable parsing error logging */ | ||
fd_log_level_stderr_set(4); | ||
return 0; | ||
} | ||
|
||
#define HEADER_CAP (32UL) | ||
|
||
int | ||
LLVMFuzzerTestOneInput( uchar const * data, | ||
ulong size ) { | ||
|
||
/* parse request in one go */ | ||
|
||
do { | ||
char const * method; | ||
ulong method_len; | ||
char const * path; | ||
ulong path_len; | ||
int minor_version; | ||
struct phr_header headers[ HEADER_CAP ]; | ||
ulong header_cnt = HEADER_CAP; | ||
|
||
int res = phr_parse_request( | ||
(char const *)data, size, | ||
&method, &method_len, | ||
&path, &path_len, | ||
&minor_version, | ||
headers, &header_cnt, 0UL ); | ||
|
||
if( res==0 ) { | ||
assert( method_len < size ); | ||
assert( path_len < size ); | ||
assert( header_cnt <= HEADER_CAP ); | ||
for( ulong i=0UL; i<header_cnt; i++ ) { | ||
assert( headers[i].name_len < size ); | ||
assert( headers[i].value_len < size ); | ||
} | ||
} | ||
} while(0); | ||
|
||
/* parse request byte by byte */ | ||
|
||
do { | ||
char const * method; | ||
ulong method_len; | ||
char const * path; | ||
ulong path_len; | ||
int minor_version; | ||
struct phr_header headers[ HEADER_CAP ]; | ||
ulong header_cnt = HEADER_CAP; | ||
int ok = 0; | ||
|
||
for( ulong cursor=0UL; cursor<size; cursor++ ) { | ||
int res = phr_parse_request( | ||
(char const *)data + cursor, 1UL, | ||
&method, &method_len, | ||
&path, &path_len, | ||
&minor_version, | ||
headers, &header_cnt, 0UL ); | ||
if( res>0 ) { | ||
ok = 1; | ||
break; | ||
} | ||
if( res==-1 ) break; | ||
assert( res==-2 ); | ||
} | ||
|
||
if( ok ) { | ||
assert( method_len < size ); | ||
assert( path_len < size ); | ||
assert( header_cnt <= HEADER_CAP ); | ||
for( ulong i=0UL; i<header_cnt; i++ ) { | ||
assert( headers[i].name_len < size ); | ||
assert( headers[i].value_len < size ); | ||
} | ||
} | ||
} while(0); | ||
|
||
return 0; | ||
} |