LCOV - code coverage report
Current view: top level - util/net - fuzz_pcap.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 7 7 100.0 %
Date: 2024-11-13 11:58:15 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             : #include <unistd.h>
       8             : 
       9             : #include "../fd_util.h"
      10             : #include "../../util/sanitize/fd_fuzz.h"
      11             : #include "./fd_pcap.h"
      12             : 
      13             : int
      14             : LLVMFuzzerInitialize( int  *   argc,
      15          18 :                       char *** argv ) {
      16             :   /* Set up shell without signal handlers */
      17          18 :   putenv( "FD_LOG_BACKTRACE=0" );
      18          18 :   fd_boot( argc, argv );
      19          18 :   atexit( fd_halt );
      20             : 
      21             :   /* Disable parsing error logging */
      22          18 :   fd_log_level_stderr_set(4);
      23          18 :   return 0;
      24          18 : }
      25             : 
      26             : int
      27             : LLVMFuzzerTestOneInput( uchar const * data,
      28             :                         ulong         size ) {
      29             : 
      30             : /* > Before glibc 2.22, if size is specified as zero, fmemopen() fails with the error EINVAL.
      31             :    - https://man7.org/linux/man-pages/man3/fmemopen.3.html */
      32             : if( FD_UNLIKELY( size==0UL ) ) return 0;
      33             : 
      34             :   FILE * file = fmemopen( (void *)data, size, "rb" );
      35             :   FD_TEST( file );
      36             : 
      37             :   /* Open "pcap". */
      38             :   fd_pcap_iter_t * pcap = fd_pcap_iter_new( file );
      39             :   if ( FD_LIKELY( pcap ) ) {
      40             :     FD_FUZZ_MUST_BE_COVERED;
      41             :     /* Loop over all packets */
      42             :     uchar buf[128];
      43             :     long  pkt_ts;
      44             :     while( fd_pcap_iter_next(pcap, &buf, sizeof(buf), &pkt_ts) > 0 ) {}
      45             : 
      46             :     /* Release pcap */
      47             :     FD_TEST( fd_pcap_iter_delete( pcap ) != NULL );
      48             :   }
      49             : 
      50             :   FD_TEST( 0==fclose( file ) );
      51             : 
      52             :   FD_FUZZ_MUST_BE_COVERED;
      53             :   return 0;
      54             : }

Generated by: LCOV version 1.14