LCOV - code coverage report
Current view: top level - ballet/base58 - fuzz_base58_garbage.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 6 14 42.9 %
Date: 2024-11-13 11:58:15 Functions: 1 2 50.0 %

          Line data    Source code
       1             : #if !FD_HAS_HOSTED
       2             : #error "This target requires FD_HAS_HOSTED"
       3             : #endif
       4             : 
       5             : #include <stdio.h>
       6             : #include <stdlib.h>
       7             : 
       8             : #include "../../util/fd_util.h"
       9             : #include "../../util/sanitize/fd_fuzz.h"
      10             : #include "fd_base58.h"
      11             : 
      12             : int
      13             : LLVMFuzzerInitialize( int  *   argc,
      14          18 :                       char *** argv ) {
      15             :   /* Set up shell without signal handlers */
      16          18 :   putenv( "FD_LOG_BACKTRACE=0" );
      17          18 :   fd_boot( argc, argv );
      18          18 :   atexit( fd_halt );
      19          18 :   return 0;
      20          18 : }
      21             : 
      22             : /* touch reads every byte in the given memory region.  This is done to
      23             :    allow ASan to crash the program if uninitialized data is given to
      24             :    this function. */
      25             : 
      26             : static void __attribute__((noinline))
      27             : touch( void * in,
      28           0 :        ulong  in_sz ) {
      29           0 :   uchar * _in = in;
      30           0 :   ulong   x   = 0UL;
      31           0 :   for( ulong i=0UL; i<in_sz; i++ ) {
      32           0 :     x ^= _in[i];
      33           0 :   }
      34           0 :   FD_COMPILER_UNPREDICTABLE( x );
      35           0 : }
      36             : 
      37             : int
      38             : LLVMFuzzerTestOneInput( uchar const * data,
      39             :                         ulong         data_sz ) {
      40             : 
      41             :   /* Input must be a cstr */
      42             :   char * cstr = malloc( data_sz+1UL );
      43             :   FD_TEST( cstr );
      44             :   memcpy( cstr, data, data_sz );
      45             :   cstr[ data_sz ]='\0';
      46             : 
      47             :   do {
      48             :     uchar out[32];
      49             :     if( fd_base58_decode_32( cstr, out ) ) {
      50             :       FD_FUZZ_MUST_BE_COVERED;
      51             :       touch( out, sizeof(out) );
      52             :     }
      53             :   } while(0);
      54             : 
      55             :   do {
      56             :     uchar out[64];
      57             :     if( fd_base58_decode_64( cstr, out ) ) {
      58             :       FD_FUZZ_MUST_BE_COVERED;
      59             :       touch( out, sizeof(out) );
      60             :     }
      61             :   } while(0);
      62             : 
      63             :   free( cstr );
      64             :   FD_FUZZ_MUST_BE_COVERED;
      65             :   return 0;
      66             : }

Generated by: LCOV version 1.14