Line data Source code
1 : #if !FD_HAS_HOSTED 2 : #error "This target requires FD_HAS_HOSTED" 3 : #endif 4 : 5 : #include <assert.h> 6 : #include <stdio.h> 7 : #include <stdlib.h> 8 : 9 : #include "../../util/fd_util.h" 10 : #include "../../util/sanitize/fd_fuzz.h" 11 : #include "fd_base64.h" 12 : 13 : /* fuzz_base64_dec verifies that Base64 decoding is safe against 14 : untrusted inputs. */ 15 : 16 : int 17 : LLVMFuzzerInitialize( int * argc, 18 12 : char *** argv ) { 19 : /* Set up shell without signal handlers */ 20 12 : putenv( "FD_LOG_BACKTRACE=0" ); 21 12 : setenv( "FD_LOG_PATH", "", 0 ); 22 12 : fd_boot( argc, argv ); 23 12 : atexit( fd_halt ); 24 12 : fd_log_level_core_set(3); /* crash on warning log */ 25 12 : return 0; 26 12 : } 27 : 28 : int 29 : LLVMFuzzerTestOneInput( uchar const * data, 30 : ulong data_sz ) { 31 : 32 : ulong dec_sz = FD_BASE64_DEC_SZ( data_sz ); 33 : assert( dec_sz < data_sz+4UL ); 34 : 35 : uchar * dec = malloc( data_sz ); 36 : assert( dec ); 37 : 38 : long dec_res = fd_base64_decode( dec, (char const *)data, data_sz ); 39 : if ( dec_res>=0L ) { 40 : FD_FUZZ_MUST_BE_COVERED; 41 : } else if ( dec_res==-1L ) { 42 : FD_FUZZ_MUST_BE_COVERED; 43 : } else { 44 : abort(); 45 : } 46 : 47 : free( dec ); 48 : FD_FUZZ_MUST_BE_COVERED; 49 : return 0; 50 : }