Skip to content

ServerSocket: demote OP_IDCHANGE sanity checks to debug logs (#610) - #613

Merged
mrjimenez merged 1 commit into
amule-project:masterfrom
got3nks:fix/serversocket-idchange-asserts
May 15, 2026
Merged

ServerSocket: demote OP_IDCHANGE sanity checks to debug logs (#610)#613
mrjimenez merged 1 commit into
amule-project:masterfrom
got3nks:fix/serversocket-idchange-asserts

Conversation

@got3nks

@got3nks got3nks commented May 15, 2026

Copy link
Copy Markdown
Contributor

Summary

A misbehaving server can put its own IP in the dwServerReportedIP field of the OP_IDCHANGE reply instead of the client's, which trips wxFAIL / wxASSERT during the parse at ServerSocket.cpp:279,282. mifritscher2 hit this in #610 connecting to "Test_server with nat_traversal v0.6". Per his point, assertions should signal corrupted internal state, not malformed input from a remote peer.

Why it's safe to demote

The downstream consumer at ServerSocket.cpp:327 only reads dwServerReportedIP when new_id is LowID:

if (::IsLowID(new_id) && dwServerReportedIP != 0) {
    theApp->SetPublicIP(dwServerReportedIP);
}

So on HighID (the case both asserts target) the bogus value is silently ignored regardless of whether the assert fires. The asserts therefore never guarded any behaviour — they only existed to flag protocol oddity.

Change

Replace wxFAIL and wxASSERT(...) with AddDebugLogLineN(logServer, ...) lines that record the offending value for diagnosis. Behaviour on real servers is unchanged; debug builds no longer abort on contact with non-conforming servers.

// before
if (::IsLowID(dwServerReportedIP)){
    wxFAIL;
    dwServerReportedIP = 0;
}
wxASSERT( dwServerReportedIP == new_id || ::IsLowID(new_id) );

// after
if (::IsLowID(dwServerReportedIP)){
    AddDebugLogLineN(logServer, ... "LowID-shaped value; ignoring" ...);
    dwServerReportedIP = 0;
}
if (dwServerReportedIP != 0 && !::IsLowID(new_id) && dwServerReportedIP != new_id) {
    AddDebugLogLineN(logServer, ... "doesn't match assigned HighID; ignoring" ...);
}

Closes #610.

…roject#610)

A misbehaving server (e.g. the "Test_server with nat_traversal v0.6"
reported in amule-project#610) can put its own IP in the dwServerReportedIP field
instead of the client's, which trips wxFAIL / wxASSERT during the
OP_IDCHANGE parse. Both checks are purely diagnostic -- the downstream
consumer at line 327 only uses dwServerReportedIP when new_id is
LowID, so the bogus HighID value is silently ignored anyway -- but
they crash debug builds for users connecting to weird servers.

Replace the assertions with AddDebugLogLineN(logServer, ...) lines
that record the bogus value for diagnosis without aborting. As
mifritscher2 noted, assertions should signal corrupted internal
state, not malformed input from a remote peer.

Reported by mifritscher2.
@mrjimenez
mrjimenez merged commit 54c6aa2 into amule-project:master May 15, 2026
12 checks passed
@got3nks
got3nks deleted the fix/serversocket-idchange-asserts branch May 15, 2026 13:42
mrjimenez pushed a commit that referenced this pull request May 15, 2026
CFileDataIO::WriteStringCore wxFAIL_MSGs when asked to serialise a
string larger than 0xFFFF bytes with a uint16 length prefix. The
intent (per the surrounding comment) is to flag peer-supplied data
that expands past 16 bits after ISO8859-1 -> UTF-8 conversion --
exactly the "external data should not trigger an assertion" pattern
that PR #613 addressed for OP_IDCHANGE.

The immediately-following code already does the right thing: it
truncates real_length to 0xFFFF and adjusts sLength accordingly, so
release builds silently absorb the oversized input. Debug builds,
however, abort on what is harmless input -- crashing amuled on every
periodic save where any single Kad contact field has been poisoned
(see #246, drzraf 2021 and fekir 2024).

Replace wxFAIL_MSG with AddDebugLogLineN(logCFile, ...) that records
the original byte count for diagnosis without aborting. The
truncation path is unchanged; on-disk format is unchanged.

Same shape as PR #613 / issue #610.

Reported by drzraf and fekir.
got3nks added a commit to got3nks/amule that referenced this pull request Jul 26, 2026
…oject#613)

Persist the Local/Global/Kad search type across restarts, and save list column widths synchronously in SaveGUIPrefs() so they survive the hide-on-close / tray-Exit path. Both cross-platform. Addresses amule-project#608 (bugs 2 & 3).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Assertion while trying to connect to "Test_server" (ip 171.25.158.106, port 4661)

2 participants