fuzz: torcontrol: drive the control connection over a mocked socket

bitcoin/bitcoin: PR #36822

2 suggestions

Optional improvements

Link

[suggestion] · Offered-method check counts AUTH lines the controller ignores

The fuzz harness counts ignored or overridden AUTH lines as offers, allowing authentication based on async messages, error replies, or superseded methods to pass its offered-method assertions.

Location: src/test/fuzz/torcontrol.cpp:148 (head).

Details and suggested fix

RecordLine() records every written AUTH line, and Offered() unions its methods into a connection-wide set. In contrast, ProcessBuffer() discards messages whose terminating line has code ≥600, while protocolinfo_cb() requires code 250 and uses the last METHODS assignment in the reply. The generators already produce async messages, non-250 authentication replies, and multiple AUTH lines. A controller regression accepting those ignored methods therefore passes the corresponding Offered() assertion because the triggering line also authorizes it in the oracle. ProvedCookie() similarly counts challenges from non-250 replies, although authchallenge_cb() rejects them.

Buffer authentication data until the message's space-terminated line arrives, using the same short-line and code parsing rules as ProcessBuffer(). Retain data only for code 250 and retain only the last METHODS assignment within each message. Filter by the terminating code, not each line's code: 650-AUTH ... followed by 250 OK is delivered as a code-250 reply. This tighter check still depends only on written bytes, not correspondence with unanswered.


Link

[suggestion] · SAFECOOKIE proof assertion is buried in reply-generation changes

The series introduces the SAFECOOKIE proof invariant inside the reply-answering commit, without naming it in the message, then restructures it in the next commit, making that check harder to review independently.

Location: src/test/fuzz/torcontrol.cpp:178 at 43e8576f5eb2 (commit) (commit).

Details and suggested fix

Commit 43e8576f5eb2cf8854fa13269e35f3c709392d8b adds matching-reply generation together with challenges, written-line recording, RecordChallenge(), ProvedCookie(), and the proof assertion. Its message names matching replies and the split/inject assertion, but not this authentication invariant. Commit 66f7fd5250eab295bebc4ab33522f8a315dc2c93 then renames the recorder to RecordLine() and restructures the authentication branch to add offered-method checks. Move the challenge-recording machinery, ProvedCookie(), and its assertion into a named commit between those two commits. It can introduce RecordLine() directly, leaving the following commit to add AUTH handling. Keep SafeCookieHash, client-nonce capture, and ConsumeAuthChallengeLine() in the reply-answering commit because generation needs them independently. This leaves the final tree unchanged while separating review of generated replies from review of the proof invariant.


Coverage details