LCOV - code coverage report
Current view: top level - test/fuzz - fuzz_descriptor.c (source / functions) Hit Total Coverage
Test: lcov.info Lines: 32 33 97.0 %
Date: 2021-11-24 03:28:48 Functions: 6 6 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/nodelist/torcert.h"
      10             : #include "feature/keymgt/loadkey.h"
      11             : #include "test/fuzz/fuzzing.h"
      12             : 
      13             : static int
      14          22 : mock_check_tap_onion_key_crosscert__nocheck(const uint8_t *crosscert,
      15             :                                    int crosscert_len,
      16             :                                    const crypto_pk_t *onion_pkey,
      17             :                                    const ed25519_public_key_t *master_id_pkey,
      18             :                                    const uint8_t *rsa_id_digest)
      19             : {
      20          22 :   tor_assert(crosscert && onion_pkey && master_id_pkey && rsa_id_digest);
      21             :   /* we could look at crosscert[..] */
      22          22 :   (void) crosscert_len;
      23          22 :   return 0;
      24             : }
      25             : 
      26             : static void
      27        1182 : mock_dump_desc__nodump(const char *desc, const char *type)
      28             : {
      29        1182 :   (void)desc;
      30        1182 :   (void)type;
      31        1182 : }
      32             : 
      33             : static int
      34         156 : mock_router_produce_hash_final__nohash(char *digest,
      35             :                                        const char *start, size_t len,
      36             :                                        digest_algorithm_t alg)
      37             : {
      38         156 :   (void)start;
      39         156 :   (void)len;
      40             :   /* we could look at start[..] */
      41         156 :   if (alg == DIGEST_SHA1)
      42         156 :     memset(digest, 0x01, 20);
      43             :   else
      44           0 :     memset(digest, 0x02, 32);
      45         156 :   return 0;
      46             : }
      47             : 
      48             : int
      49        1185 : fuzz_init(void)
      50             : {
      51        1185 :   disable_signature_checking();
      52        1185 :   MOCK(check_tap_onion_key_crosscert,
      53             :        mock_check_tap_onion_key_crosscert__nocheck);
      54        1185 :   MOCK(dump_desc, mock_dump_desc__nodump);
      55        1185 :   MOCK(router_compute_hash_final, mock_router_produce_hash_final__nohash);
      56        1185 :   ed25519_init();
      57        1185 :   return 0;
      58             : }
      59             : 
      60             : int
      61        1185 : fuzz_cleanup(void)
      62             : {
      63        1185 :   return 0;
      64             : }
      65             : 
      66             : int
      67        1185 : fuzz_main(const uint8_t *data, size_t sz)
      68             : {
      69        1185 :   routerinfo_t *ri;
      70        1185 :   const char *str = (const char*) data;
      71        1185 :   ri = router_parse_entry_from_string((const char *)str,
      72             :                                       str+sz,
      73             :                                       0, 0, 0, NULL);
      74        1185 :   if (ri) {
      75           3 :     log_debug(LD_GENERAL, "Parsing okay");
      76           3 :     routerinfo_free(ri);
      77             :   } else {
      78        1182 :     log_debug(LD_GENERAL, "Parsing failed");
      79             :   }
      80        1185 :   return 0;
      81             : }

Generated by: LCOV version 1.14