LCOV - code coverage report
Current view: top level - waltz/resolv - fuzz_dns_parse.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 7 7 100.0 %
Date: 2025-07-01 05:00:49 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #include "../../util/fd_util.h"
       2             : #include "fd_lookup.h"
       3             : #include "fd_lookup_name.c"
       4             : 
       5             : #include <assert.h>
       6             : #include <stdlib.h>
       7             : 
       8             : int
       9             : LLVMFuzzerInitialize( int *argc,
      10          15 :                       char ***argv ) {
      11             :   /* Set up shell without signal handlers */
      12          15 :   putenv( "FD_LOG_BACKTRACE=0" );
      13          15 :   fd_boot( argc, argv );
      14          15 :   (void) atexit( fd_halt );
      15          15 :   fd_log_level_core_set( 1 ); /* crash on info log */
      16          15 :   return 0;
      17          15 : }
      18             : 
      19             : int
      20             : LLVMFuzzerTestOneInput( uchar const *data,
      21             :                         ulong        size ) {
      22             :   /* Need at least one byte for rrtype selector and some payload. */
      23             :   if( size<2UL ) {
      24             :     return 0;
      25             :   }
      26             : 
      27             :   uint8_t rrtype = (data[ 0 ] & 1u) ? RR_A : RR_AAAA;
      28             : 
      29             :   struct address addrs[ MAXADDRS ] = {0};
      30             :   char           canon[ 256 ]      = {0};
      31             :   struct dpc_ctx ctx = {
      32             :       .addrs = addrs,
      33             :       .canon = canon,
      34             :       .cnt   = 0,
      35             :       .rrtype = rrtype,
      36             :   };
      37             : 
      38             :   fd_dns_parse( data+1, (int) (size-1UL), dns_parse_callback, &ctx );
      39             : 
      40             :   /* Basic post-conditions */
      41             :   FD_TEST( ctx.cnt>=0 );
      42             :   FD_TEST( ctx.cnt<=MAXADDRS );
      43             : 
      44             :   if( ctx.cnt>0 ) {
      45             :     int expected_family = fd_int_if( (rrtype==RR_A), AF_INET, AF_INET6  );
      46             :     FD_TEST( ctx.addrs[ 0 ].family==expected_family );
      47             :   }
      48             : 
      49             :   /* Canonical name, if set, must be a valid C string */
      50             :   if( canon[ 0 ] ) {
      51             :     FD_TEST( strlen( canon ) < sizeof(canon));
      52             :   }
      53             : 
      54             :   return 0;
      55             : }

Generated by: LCOV version 1.14