LCOV - code coverage report
Current view: top level - ballet/base64 - fuzz_base64_dec.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 6 6 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 <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 :   return 0;
      24          18 : }
      25             : 
      26             : int
      27             : LLVMFuzzerTestOneInput( uchar const * data,
      28             :                         ulong         data_sz ) {
      29             : 
      30             :   ulong dec_sz = FD_BASE64_DEC_SZ( data_sz );
      31             :   assert( dec_sz < data_sz+4UL );
      32             : 
      33             :   uchar * dec = malloc( data_sz );
      34             :   assert( dec );
      35             : 
      36             :   long dec_res = fd_base64_decode( dec, (char const *)data, data_sz );
      37             :   if ( dec_res>=0L ) {
      38             :     FD_FUZZ_MUST_BE_COVERED;
      39             :   } else if ( dec_res==-1L ) {
      40             :     FD_FUZZ_MUST_BE_COVERED;
      41             :   } else {
      42             :     abort();
      43             :   }
      44             : 
      45             :   free( dec );
      46             :   FD_FUZZ_MUST_BE_COVERED;
      47             :   return 0;
      48             : }

Generated by: LCOV version 1.14