LCOV - code coverage report
Current view: top level - ballet/base64 - fuzz_base64_dec.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 7 7 100.0 %
Date: 2025-01-08 12:08:44 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 <assert.h>
       6             : #include <stdio.h>
       7             : #include <stdlib.h>
       8             : 
       9             : #include "../../util/fd_util.h"
      10             : #include "../../util/sanitize/fd_fuzz.h"
      11             : #include "fd_base64.h"
      12             : 
      13             : /* fuzz_base64_dec verifies that Base64 decoding is safe against
      14             :    untrusted inputs. */
      15             : 
      16             : int
      17             : LLVMFuzzerInitialize( int  *   argc,
      18          18 :                       char *** argv ) {
      19             :   /* Set up shell without signal handlers */
      20          18 :   putenv( "FD_LOG_BACKTRACE=0" );
      21          18 :   fd_boot( argc, argv );
      22          18 :   atexit( fd_halt );
      23          18 :   fd_log_level_core_set(3); /* crash on warning log */
      24          18 :   return 0;
      25          18 : }
      26             : 
      27             : int
      28             : LLVMFuzzerTestOneInput( uchar const * data,
      29             :                         ulong         data_sz ) {
      30             : 
      31             :   ulong dec_sz = FD_BASE64_DEC_SZ( data_sz );
      32             :   assert( dec_sz < data_sz+4UL );
      33             : 
      34             :   uchar * dec = malloc( data_sz );
      35             :   assert( dec );
      36             : 
      37             :   long dec_res = fd_base64_decode( dec, (char const *)data, data_sz );
      38             :   if ( dec_res>=0L ) {
      39             :     FD_FUZZ_MUST_BE_COVERED;
      40             :   } else if ( dec_res==-1L ) {
      41             :     FD_FUZZ_MUST_BE_COVERED;
      42             :   } else {
      43             :     abort();
      44             :   }
      45             : 
      46             :   free( dec );
      47             :   FD_FUZZ_MUST_BE_COVERED;
      48             :   return 0;
      49             : }

Generated by: LCOV version 1.14