Skip to content

Commit 3037f95

Browse files
snapshots: fuzz ssarchive parser
1 parent 0d0a5d6 commit 3037f95

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/discof/restore/Local.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ $(call make-unit-test,test_ssmanifest_parser,utils/test_ssmanifest_parser,fd_dis
1616
ifdef FD_HAS_HOSTED
1717
$(call make-fuzz-test,fuzz_snapshot_parser,utils/fuzz_snapshot_parser,fd_discof fd_flamenco fd_ballet fd_util)
1818
$(call make-fuzz-test,fuzz_ssmanifest_parser,utils/fuzz_ssmanifest_parser,fd_discof fd_flamenco fd_ballet fd_util)
19+
$(call make-fuzz-test,fuzz_ssarchive_parser,utils/fuzz_ssarchive_parser,fd_discof fd_flamenco fd_ballet fd_util)
1920
endif
2021

2122
endif
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include "fd_ssarchive.h"
2+
3+
#if !FD_HAS_HOSTED
4+
#error "This target requires FD_HAS_HOSTED"
5+
#endif
6+
7+
#include <stdlib.h>
8+
#include <assert.h>
9+
10+
int
11+
LLVMFuzzerInitialize( int * argc,
12+
char *** argv ) {
13+
/* Set up shell without signal handlers */
14+
putenv( "FD_LOG_BACKTRACE=0" );
15+
fd_boot( argc, argv );
16+
atexit( fd_halt );
17+
fd_log_level_core_set ( 4 );
18+
fd_log_level_logfile_set( 4 );
19+
20+
return 0;
21+
}
22+
23+
int
24+
LLVMFuzzerTestOneInput( uchar const * data,
25+
ulong size ) {
26+
ulong full_slot;
27+
ulong incremental_slot;
28+
uchar decoded_hash[ FD_HASH_FOOTPRINT ];
29+
30+
char* name_cstr = (char *)malloc( size + 1UL );
31+
assert( name_cstr );
32+
fd_cstr_fini( fd_cstr_append_text( fd_cstr_init( name_cstr ), (char const *)data, size ) );
33+
34+
fd_ssarchive_parse_filename( name_cstr, &full_slot, &incremental_slot, decoded_hash );
35+
36+
free( name_cstr );
37+
return 0;
38+
}

0 commit comments

Comments
 (0)