LCOV - code coverage report
Current view: top level - disco/bundle - fuzz_bundle_auth_resp.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 9 9 100.0 %
Date: 2025-07-01 05:00:49 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 "fd_bundle_auth.h"
       6             : 
       7             : #include <stdlib.h>
       8             : 
       9             : /* At least one byte is required for an operation selector */
      10             : #define MIN_INPUT_SIZE (1)
      11             : 
      12          15 : int LLVMFuzzerInitialize( int *argc, char ***argv ) {
      13          15 :   putenv( "FD_LOG_BACKTRACE=0" );
      14             : 
      15          15 :   fd_boot( argc, argv );
      16             : 
      17          15 :   atexit( fd_halt );
      18             : 
      19          15 :   fd_log_level_core_set( 4 );
      20          15 :   fd_log_level_stderr_set( 4 );
      21          15 :   fd_log_level_logfile_set( 4 );
      22             : 
      23          15 :   return 0;
      24          15 : }
      25             : 
      26             : int LLVMFuzzerTestOneInput( const uchar *data, ulong size ) {
      27             :   if( size < MIN_INPUT_SIZE ) {
      28             :     return 0;
      29             :   }
      30             : 
      31             :   uchar const op = data[ 0 ] & 0x3U;
      32             :   uchar const *payload = data+1;
      33             :   ulong payload_sz = size-1UL;
      34             : 
      35             :   fd_bundle_auther_t auther = {0};
      36             :   fd_bundle_auther_t *pAuther = fd_bundle_auther_init( &auther );
      37             : 
      38             :   int rc = 0;
      39             : 
      40             :   switch ( op ) {
      41             :     case 0:
      42             :       fd_bundle_auther_handle_request_fail( pAuther );
      43             :       break;
      44             :     case 1:
      45             :       rc = fd_bundle_auther_handle_challenge_resp( pAuther, payload, payload_sz );
      46             :       if( rc ) {
      47             :         FD_TEST( pAuther->state==FD_BUNDLE_AUTH_STATE_REQ_TOKENS );
      48             :       } else {
      49             :         FD_TEST( pAuther->state==FD_BUNDLE_AUTH_STATE_REQ_CHALLENGE );
      50             :       }
      51             :       break;
      52             :     case 2:
      53             :       rc = fd_bundle_auther_handle_tokens_resp( pAuther, payload, payload_sz );
      54             :       if( rc ) {
      55             :         FD_TEST( pAuther->state==FD_BUNDLE_AUTH_STATE_DONE_WAIT );
      56             :       } else {
      57             :         FD_TEST( pAuther->state==FD_BUNDLE_AUTH_STATE_REQ_CHALLENGE );
      58             :       }
      59             :       break;
      60             :     case 3:
      61             :       pAuther->state = FD_BUNDLE_AUTH_STATE_DONE_WAIT;
      62             :       fd_bundle_auther_reset( pAuther );
      63             :       FD_TEST( pAuther->state==FD_BUNDLE_AUTH_STATE_REQ_CHALLENGE );
      64             :       break;
      65             :   }
      66             : 
      67             :   FD_TEST( pAuther->state<=FD_BUNDLE_AUTH_STATE_DONE_WAIT );
      68             :   FD_TEST( pAuther->needs_poll<=1 );
      69             :   FD_TEST( pAuther->access_token_sz<=sizeof(pAuther->access_token) );
      70             : 
      71             :   (void) rc; /* suppress unused-var warning when assertions are off */
      72             : 
      73             :   return 0;
      74             : }

Generated by: LCOV version 1.14