LCOV - code coverage report
Current view: top level - test/fuzz - fuzz_extrainfo.c (source / functions) Hit Total Coverage
Test: lcov.info Lines: 28 29 96.6 %
Date: 2021-11-24 03:28:48 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /* Copyright (c) 2016-2021, The Tor Project, Inc. */
       2             : /* See LICENSE for licensing information */
       3             : #define SIGCOMMON_PRIVATE
       4             : #include "core/or/or.h"
       5             : #include "feature/dirparse/routerparse.h"
       6             : #include "feature/dirparse/sigcommon.h"
       7             : #include "feature/dirparse/unparseable.h"
       8             : #include "feature/nodelist/routerlist.h"
       9             : #include "feature/relay/routerkeys.h"
      10             : #include "test/fuzz/fuzzing.h"
      11             : 
      12             : static void
      13         436 : mock_dump_desc__nodump(const char *desc, const char *type)
      14             : {
      15         436 :   (void)desc;
      16         436 :   (void)type;
      17         436 : }
      18             : 
      19             : static int
      20          93 : mock_router_produce_hash_final__nohash(char *digest,
      21             :                                        const char *start, size_t len,
      22             :                                        digest_algorithm_t alg)
      23             : {
      24          93 :   (void)start;
      25          93 :   (void)len;
      26             :   /* we could look at start[..] */
      27          93 :   if (alg == DIGEST_SHA1)
      28          93 :     memset(digest, 0x01, 20);
      29             :   else
      30           0 :     memset(digest, 0x02, 32);
      31          93 :   return 0;
      32             : }
      33             : 
      34             : int
      35         441 : fuzz_init(void)
      36             : {
      37         441 :   disable_signature_checking();
      38         441 :   MOCK(dump_desc, mock_dump_desc__nodump);
      39         441 :   MOCK(router_compute_hash_final, mock_router_produce_hash_final__nohash);
      40         441 :   ed25519_init();
      41         441 :   return 0;
      42             : }
      43             : 
      44             : int
      45         441 : fuzz_cleanup(void)
      46             : {
      47         441 :   return 0;
      48             : }
      49             : 
      50             : int
      51         441 : fuzz_main(const uint8_t *data, size_t sz)
      52             : {
      53         441 :   extrainfo_t *ei;
      54         441 :   const char *str = (const char*) data;
      55         441 :   int again = 0;
      56         441 :   ei = extrainfo_parse_entry_from_string((const char *)str,
      57             :                                          str+sz,
      58             :                                          0, NULL, &again);
      59         441 :   if (ei) {
      60           5 :     log_debug(LD_GENERAL, "Parsing okay");
      61           5 :     extrainfo_free(ei);
      62             :   } else {
      63         436 :     log_debug(LD_GENERAL, "Parsing failed");
      64             :   }
      65         441 :   return 0;
      66             : }
      67             : 

Generated by: LCOV version 1.14