fuzz: addrman, avoid `ConsumeDeserializable` when possible #27918

pull brunoerg wants to merge 1 commits into bitcoin:master from brunoerg:2023-06-fuzz-addrman-deserializable changing 1 files +7 −26
  1. brunoerg commented at 12:07 PM on June 20, 2023: contributor

    Using specific functions like ConsumeService, ConsumeAddress and ConsumeNetAddr may be more effective than using ConsumeDeserializable. They always return some value while ConsumeDeserializable may return std::nullopt.

    E.g.: In this part of the code, if op_net_addr is std::nullopt, we basically generated the addresses (if so) unnecessarily, because we won't be able to use them:

    std::vector<CAddress> addresses;
    LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
        const std::optional<CAddress> opt_address = ConsumeDeserializable<CAddress>(fuzzed_data_provider);
        if (!opt_address) {
            break;
        }
        addresses.push_back(*opt_address);
    }
    const std::optional<CNetAddr> opt_net_addr = ConsumeDeserializable<CNetAddr>(fuzzed_data_provider);
    if (opt_net_addr) {
        addr_man.Add(addresses, *opt_net_addr, std::chrono::seconds{ConsumeTime(fuzzed_data_provider, 0, 100000000)});
    }
    

    Also, if we are not calling Add effectively, it would also be affect other functions that may "depend" on it.

  2. fuzz: addrman, avoid `ConsumeDeserializable` when possible
    `ConsumeDeserializable` may return `std::nullopt`, prefer
    to call specific functions such as `ConsumeService`and
    `ConsumeNetAddr` which always return a value.
    025fda0a76
  3. DrahtBot commented at 12:07 PM on June 20, 2023: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK dergoegge

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #25284 (net: Use serialization parameters for CAddress serialization by MarcoFalke)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  4. DrahtBot added the label Tests on Jun 20, 2023
  5. maflcko commented at 12:31 PM on June 20, 2023: member

    lgtm

    In theory one could use the nullopt state to break a loop or exit early (for example with a different exit code, c.f. #27552), but given that this fuzz target checks ConsumeBool (which returns false on empty input) on each iteration before continuing, this seems fine for this fuzz target.

  6. fanquake requested review from dergoegge on Aug 3, 2023
  7. dergoegge approved
  8. dergoegge commented at 1:00 PM on August 3, 2023: member

    Code review ACK 025fda0a76893d09d19ec9a6c0ba86ad11c466f7

  9. in src/test/fuzz/addrman.cpp:310 in 025fda0a76
     306 | @@ -326,4 +307,4 @@ FUZZ_TARGET_INIT(addrman_serdeser, initialize_addrman)
     307 |      data_stream << addr_man1;
     308 |      data_stream >> addr_man2;
     309 |      assert(addr_man1 == addr_man2);
     310 | -}
     311 | +}
    


    fanquake commented at 4:32 PM on August 3, 2023:

    It'd be good to avoid making unrelated changes like this (deleting the file ending newline).

  10. fanquake merged this on Aug 3, 2023
  11. fanquake closed this on Aug 3, 2023

  12. sidhujag referenced this in commit 262059515c on Aug 9, 2023
  13. bitcoin locked this on Aug 2, 2024

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-05-02 03:13 UTC

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