net: parse NAT-PMP result code as 16-bit BE in PCP fallback #36800

pull rahadbhuiya wants to merge 1 commits into bitcoin:master from rahadbhuiya:net-pcp-result-code-fix changing 2 files +39 −1
  1. rahadbhuiya commented at 6:24 AM on November 8, 2026: none

    When checking whether a gateway replied with NAT-PMP unsupported version (RFC 6887 appendix A and RFC 6886 section 3.5), PCPRequestPortMap mistakenly used PCP_RESPONSE_HDR_RESULT_OFS (3) and compared only a single byte against NATPMP_RESULT_UNSUPP_VERSION.

    NAT-PMP result codes are 16-bit big-endian values starting at offset 2 (NATPMP_RESPONSE_HDR_RESULT_OFS). A 16-bit result code with low byte 1 and a non-zero high byte (such as 0x0101) would previously be incorrectly treated as UNSUPP_VERSION.

    This PR fixes the check to use ReadBE16(response.data() + NATPMP_RESPONSE_HDR_RESULT_OFS) matching the rest of pcp.cpp (lines 348 and 390), and uses NATPMP_HDR_VERSION_OFS for the version field offset. A unit test is added to pcp_tests.cpp.

  2. net: parse NAT-PMP result code as 16-bit BE in PCP fallback
    When checking whether a gateway replied with NAT-PMP unsupported version (RFC 6887 appendix A and RFC 6886 section 3.5), PCPRequestPortMap mistakenly used PCP_RESPONSE_HDR_RESULT_OFS (3) and compared only a single byte against NATPMP_RESULT_UNSUPP_VERSION.
    
    NAT-PMP result codes are 16-bit big-endian values starting at offset 2 (NATPMP_RESPONSE_HDR_RESULT_OFS). A 16-bit result code with low byte 1 and a non-zero high byte (such as 0x0101) would previously be incorrectly treated as UNSUPP_VERSION.
    
    Use ReadBE16 with NATPMP_RESPONSE_HDR_RESULT_OFS instead, matching the rest of pcp.cpp, and use NATPMP_HDR_VERSION_OFS for the version check. Add a unit test covering this case.
    aa57403920
  3. DrahtBot added the label P2P on Nov 8, 2026
  4. DrahtBot commented at 6:24 AM on November 8, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process. A summary of reviews will appear here.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

    LLM Linter (✨ experimental)

    Possible places where named args for integral literals may be used (e.g. func(x, /*named_arg=*/0) in C++, and func(x, named_arg=0) in Python):

    • src/test/pcp_tests.cpp: PCPRequestPortMap(TEST_NONCE, default_gateway_ipv4, bind_any_ipv4, 1234, 1000, g_interrupt, 1, 1000ms)

    <sup>2026-11-08 06:24:44</sup>

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-11-15 02:51 UTC

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