LCOV - code coverage report
Current view: top level - waltz/ebpf - fuzz_ebpf.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 34 34 100.0 %
Date: 2024-11-13 11:58:15 Functions: 2 2 100.0 %

          Line data    Source code
       1             : #include "fd_ebpf.h"
       2             : #include "../../util/fd_util.h"
       3             : #include "../../util/sanitize/fd_fuzz.h"
       4             : 
       5             : #include <assert.h>
       6             : #include <stdlib.h>
       7             : 
       8             : int
       9             : LLVMFuzzerInitialize( int  *   argc,
      10          18 :                       char *** argv ) {
      11             :   /* Set up shell without signal handlers */
      12          18 :   putenv( "FD_LOG_BACKTRACE=0" );
      13          18 :   fd_boot( argc, argv );
      14          18 :   atexit( fd_halt );
      15             :   /* Don't print warning log */
      16          18 :   fd_log_level_logfile_set( 4 );
      17          18 :   fd_log_level_stderr_set( 4 );
      18          18 :   return 0;
      19          18 : }
      20             : 
      21             : int
      22             : LLVMFuzzerTestOneInput( uchar const * const data,
      23           3 :                         ulong         const size ) {
      24             : 
      25             :   /* TODO: For now hardcode symbol map, as that is the usual way
      26             :            programs for programs to interact */
      27             : 
      28           3 :   static fd_ebpf_sym_t const syms[ 2 ] = {
      29           3 :     { .name = "fd_xdp_udp_dsts", .value = 10 },
      30           3 :     { .name = "fd_xdp_xsks",     .value = 20 }
      31           3 :   };
      32             : 
      33             :   /* heap allocated buffers */
      34           3 :   uchar * elf = NULL;
      35             : 
      36           3 :   do {
      37           3 :     elf = malloc( size );
      38           3 :     if( !elf ) break;
      39           3 :     fd_memcpy( elf, data, size );
      40             : 
      41           3 :     fd_ebpf_link_opts_t link_opts = {
      42           3 :       .section = "xdp",
      43           3 :       .sym     = syms,
      44           3 :       .sym_cnt = 2UL
      45           3 :     };
      46             : 
      47           3 :     fd_ebpf_link_opts_t * res = fd_ebpf_static_link( &link_opts, elf, size );
      48           3 :     if( res ) {
      49           3 :       assert( res == &link_opts );
      50           3 :       assert( ( (ulong)res->bpf >= (ulong)elf           ) &
      51           3 :               ( res->bpf_sz     <= size                 ) &
      52           3 :               ( fd_ulong_is_aligned( res->bpf_sz, 8UL ) ) );
      53           3 :     }
      54           3 :   } while(0);
      55             : 
      56           3 :   free( elf );
      57           3 :   return 0;
      58           3 : }

Generated by: LCOV version 1.14