LCOV - code coverage report
Current view: top level - ballet/base58 - fuzz_base58_garbage.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 7 15 46.7 %
Date: 2025-01-08 12:08:44 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 :   fd_log_level_core_set(3); /* crash on warning log */
      20          18 :   return 0;
      21          18 : }
      22             : 
      23             : /* touch reads every byte in the given memory region.  This is done to
      24             :    allow ASan to crash the program if uninitialized data is given to
      25             :    this function. */
      26             : 
      27             : static void __attribute__((noinline))
      28             : touch( void * in,
      29           0 :        ulong  in_sz ) {
      30           0 :   uchar * _in = in;
      31           0 :   ulong   x   = 0UL;
      32           0 :   for( ulong i=0UL; i<in_sz; i++ ) {
      33           0 :     x ^= _in[i];
      34           0 :   }
      35           0 :   FD_COMPILER_UNPREDICTABLE( x );
      36           0 : }
      37             : 
      38             : int
      39             : LLVMFuzzerTestOneInput( uchar const * data,
      40             :                         ulong         data_sz ) {
      41             : 
      42             :   /* Input must be a cstr */
      43             :   char * cstr = malloc( data_sz+1UL );
      44             :   FD_TEST( cstr );
      45             :   memcpy( cstr, data, data_sz );
      46             :   cstr[ data_sz ]='\0';
      47             : 
      48             :   do {
      49             :     uchar out[32];
      50             :     if( fd_base58_decode_32( cstr, out ) ) {
      51             :       FD_FUZZ_MUST_BE_COVERED;
      52             :       touch( out, sizeof(out) );
      53             :     }
      54             :   } while(0);
      55             : 
      56             :   do {
      57             :     uchar out[64];
      58             :     if( fd_base58_decode_64( cstr, out ) ) {
      59             :       FD_FUZZ_MUST_BE_COVERED;
      60             :       touch( out, sizeof(out) );
      61             :     }
      62             :   } while(0);
      63             : 
      64             :   free( cstr );
      65             :   FD_FUZZ_MUST_BE_COVERED;
      66             :   return 0;
      67             : }

Generated by: LCOV version 1.14