tests: Add fuzzing harnesses for functions in addrdb.h, net_permissions.h and timedata.h #18417

pull practicalswift wants to merge 3 commits into bitcoin:master from practicalswift:fuzzers-misc changing 4 files +144 −0
  1. practicalswift commented at 1:45 PM on March 24, 2020: contributor

    Add fuzzing harnesses for functions in addrdb.h, net_permissions.h and timedata.h.

  2. fanquake added the label Tests on Mar 24, 2020
  3. in src/test/fuzz/net_permissions.cpp:20 in 39d387e92a outdated
      15 | +
      16 | +void test_one_input(const std::vector<uint8_t>& buffer)
      17 | +{
      18 | +    FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
      19 | +    const std::string s = fuzzed_data_provider.ConsumeRandomLengthString(32);
      20 | +    const NetPermissionFlags net_permission_flags = fuzzed_data_provider.ConsumeBool() ? fuzzed_data_provider.PickValueInArray<NetPermissionFlags>({NetPermissionFlags::PF_NONE, NetPermissionFlags::PF_BLOOMFILTER, NetPermissionFlags::PF_RELAY, NetPermissionFlags::PF_FORCERELAY, NetPermissionFlags::PF_NOBAN, NetPermissionFlags::PF_MEMPOOL, NetPermissionFlags::PF_ISIMPLICIT, NetPermissionFlags::PF_ALL}) : static_cast<NetPermissionFlags>(fuzzed_data_provider.ConsumeIntegral<uint32_t>());
    


    MarcoFalke commented at 1:57 PM on March 24, 2020:

    I'd prefer to have them in multiple lines, so that adding and removing values is easier to follow in the diff and in git blame


    practicalswift commented at 2:54 PM on March 24, 2020:

    Now fixed. Considering updating .clang-format regarding this whitespace nit since it seems to be recurring (I agree with your rationale).

    Ideally the .clang-format should be written such that clang-format -i makes a PR immune against whitespace nits :)


    MarcoFalke commented at 3:03 PM on March 24, 2020:

    I think the goal of clang-format is to only add whitespace, not commas or even normalize whitespace like black does for python

  4. in src/test/fuzz/timedata.cpp:25 in 39d387e92a outdated
      20 | +    CMedianFilter<int64_t> median_filter{max_size, initial_value};
      21 | +    while (fuzzed_data_provider.remaining_bytes() > 0) {
      22 | +        (void)median_filter.median();
      23 | +        assert(median_filter.size() > 0);
      24 | +        assert(static_cast<size_t>(median_filter.size()) == median_filter.sorted().size());
      25 | +        assert(static_cast<unsigned int>(median_filter.size()) <= max_size || max_size == 0);
    


    MarcoFalke commented at 2:02 PM on March 24, 2020:

    Why is this needed?

            assert(static_cast<unsigned int>(median_filter.size()) <= max_size);
    

    practicalswift commented at 2:54 PM on March 24, 2020:

    It is needed since max_size == 0 means unbounded size as CMedianFilter is currently implemented :)

  5. tests: Add fuzzing harness for functions in addrdb.h a8695db785
  6. tests: Add fuzzing harness for functions in timedata.h 43ff0d91f8
  7. tests: Add fuzzing harness for functions in net_permissions.h 4308aa67e3
  8. practicalswift force-pushed on Mar 24, 2020
  9. in src/test/fuzz/addrdb.cpp:42 in 4308aa67e3
      37 | +            break;
      38 | +        }
      39 | +        }
      40 | +        return CBanEntry{};
      41 | +    }();
      42 | +    assert(!ban_entry.banReasonToString().empty());
    


    MarcoFalke commented at 3:02 PM on March 24, 2020:

    Would it make sense to also add an AssertEqualAfterSerializeDeserialize here?


    practicalswift commented at 3:24 PM on March 24, 2020:

    I'm afraid equality is not defined for CBanEntry. That goes for quite a few of our classes :)

  10. MarcoFalke merged this on Mar 24, 2020
  11. MarcoFalke closed this on Mar 24, 2020

  12. deadalnix referenced this in commit 72db0cf0f5 on Aug 6, 2020
  13. jasonbcox referenced this in commit 951ffba58f on Aug 6, 2020
  14. practicalswift deleted the branch on Apr 10, 2021
  15. kittywhiskers referenced this in commit 99f71fd6eb on May 7, 2022
  16. kittywhiskers referenced this in commit 33591a25be on May 7, 2022
  17. kittywhiskers referenced this in commit b053eadd52 on Jun 14, 2022
  18. kittywhiskers referenced this in commit 72e1b6a9bf on Jun 14, 2022
  19. kittywhiskers referenced this in commit a658087d5f on Jun 18, 2022
  20. kittywhiskers referenced this in commit 70e2ae1bf2 on Jul 4, 2022
  21. kittywhiskers referenced this in commit 5a67fd250e on Jul 6, 2022
  22. kittywhiskers referenced this in commit 6ee033b2da on Jul 6, 2022
  23. PastaPastaPasta referenced this in commit eefdae1a53 on Jul 12, 2022
  24. knst referenced this in commit bc81ac8806 on Jul 21, 2022
  25. DrahtBot locked this on Aug 18, 2022
Labels

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-16 15:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me