LCOV - code coverage report
Current view: top level - ballet/txn - fuzz_txn_parse.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 7 7 100.0 %
Date: 2025-03-20 12:08:36 Functions: 1 1 100.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_txn.h"
      11             : 
      12             : int
      13             : LLVMFuzzerInitialize( int  *   argc,
      14          15 :                       char *** argv ) {
      15             :   /* Set up shell without signal handlers */
      16          15 :   putenv( "FD_LOG_BACKTRACE=0" );
      17          15 :   fd_boot( argc, argv );
      18          15 :   fd_log_level_core_set(3); /* crash on warning log */
      19          15 :   atexit( fd_halt );
      20          15 :   return 0;
      21          15 : }
      22             : 
      23             : int
      24             : LLVMFuzzerTestOneInput( uchar const * data,
      25             :                         ulong         size ) {
      26             :   if( FD_UNLIKELY( size>=1232UL ) ) return -1;
      27             : 
      28             :   uchar __attribute__((aligned((alignof(fd_txn_t))))) txn_buf[ FD_TXN_MAX_SZ ];
      29             :   fd_txn_parse_counters_t counters = {0};
      30             : 
      31             :   ulong sz = fd_txn_parse( data, size, txn_buf, &counters );
      32             :   __asm__ volatile( "" : "+m,r"(sz) : : "memory" ); /* prevent optimization */
      33             : 
      34             :   if( FD_LIKELY( sz>0UL ) ) {
      35             :     FD_FUZZ_MUST_BE_COVERED;
      36             :     fd_txn_t * txn = (fd_txn_t *)txn_buf;
      37             :     FD_TEST( fd_txn_footprint( txn->instr_cnt, txn->addr_table_lookup_cnt )<=FD_TXN_MAX_SZ );
      38             :   }
      39             : 
      40             :   FD_FUZZ_MUST_BE_COVERED;
      41             :   return 0;
      42             : }

Generated by: LCOV version 1.14