net: drop connection on unknown socket family in AcceptConnection #34678

pull chriszeng1010 wants to merge 1 commits into bitcoin:master from chriszeng1010:fix-accept-unknown-sockaddr changing 1 files +2 −2
  1. chriszeng1010 commented at 4:52 am on February 26, 2026: none

    When SetSockAddr() fails in AcceptConnection(), the code logs a warning but continues processing the connection with a default empty CService address. This means ban checks, whitelist matching, and all downstream logic operate on an invalid address.

    Return early on failure instead, consistent with other error paths in the same function.

  2. net: drop connection on unknown socket family in AcceptConnection 882ed5f78e
  3. DrahtBot added the label P2P on Feb 26, 2026
  4. DrahtBot commented at 4:52 am on February 26, 2026: contributor

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

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept ACK Bortlesboat

    If your review is incorrectly listed, please copy-paste <!–meta-tag:bot-skip–> into the comment that the bot should ignore.

  5. DrahtBot added the label CI failed on Feb 28, 2026
  6. DrahtBot removed the label CI failed on Mar 2, 2026
  7. Bortlesboat commented at 10:42 pm on March 7, 2026: none

    Concept ACK on the AcceptConnection early return — continuing with a default empty CService after SetSockAddr failure means ban checks and whitelist matching run against an invalid address, which is clearly wrong.

    One question: the diff also includes a change to the ConnectNode log line (removing ConnectionTypeAsString(conn_type) from the debug log). The PR description only mentions the AcceptConnection fix. Is the logging change intentional? If so, it might be cleaner as a separate commit since the two changes are unrelated.

  8. chriszeng1010 commented at 3:36 am on March 8, 2026: none

    Concept ACK on the AcceptConnection early return — continuing with a default empty CService after SetSockAddr failure means ban checks and whitelist matching run against an invalid address, which is clearly wrong.

    One question: the diff also includes a change to the ConnectNode log line (removing ConnectionTypeAsString(conn_type) from the debug log). The PR description only mentions the AcceptConnection fix. Is the logging change intentional? If so, it might be cleaner as a separate commit since the two changes are unrelated.

    the only change is in AcceptConnection()

  9. maflcko commented at 8:57 am on March 10, 2026: member
    Was this LLM generated? What are the steps to test this? What is the output before and after the changes here?
  10. chriszeng1010 commented at 6:23 am on March 15, 2026: none

    The fix is a straightforward control flow change I made to make this consistent with other error paths in the same function (e.g. the accept() failure check just above it uses the same pattern).

    0    if (!sock) {
    1        const int nErr = WSAGetLastError();
    2        if (nErr != WSAEWOULDBLOCK) {
    3            LogInfo("socket error accept failed: %s\n", NetworkErrorString(nErr));
    4        }
    5        return;
    6    }
    

    So, when SetSockAddr() fails, addr stays as a default-constructed CService - which is a zeroed-out address (0.0.0.0:0). Then CreateNodeFromAcceptedSocket() is called with that zeroed addr.

    Testing this code path requires triggering an incoming connection, which isn’t easily reproducible in the test framework. It can’t be explicitly tested - there’s no test for AcceptConnection() in the test suite.

    This is a low risk fix, the worst case outcome is a legitimate connection gets dropped and immediately reconnects.

  11. in src/net.cpp:1747 in 882ed5f78e
    1744@@ -1745,9 +1745,9 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
    1745     CService addr;
    1746     if (!addr.SetSockAddr((const struct sockaddr*)&sockaddr, len)) {
    1747         LogWarning("Unknown socket family\n");
    


    frankomosh commented at 8:50 am on March 20, 2026:
    The LogWarning here predates this PR, but since you are already touching this block, would it be worth including sockaddr.ss_family in the message to make it more actionable for anyone debugging an unexpected socket family in the wild?

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-03-30 12:13 UTC

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