gossipwith: add flag to insist that we receive all messages.
What changed, and why it matters
This is a small change to a developer-only diagnostic tool called 'gossipwith'. It adds a new optional command-line flag that makes the tool return a failure exit code if it does not receive the expected number of messages. There is no indication this fixes a security bug or affects normal Lightning node operation.
No security action required. Treat as a normal developer-tool enhancement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch modifies devtools/gossipwith.c, adding a –must-get-max-messages flag backed by a no_early_close boolean. When set, the tool exits with status 1 instead of 0 on read failures, timeouts, or when max_messages is not reached. This is purely a testing/diagnostics convenience for the developer tool and does not alter production gossip protocol handling, cryptography, or resource limits.
Changed components
devtools/gossipwith.cInspect captured patch +15 / −3
diff --git a/devtools/gossipwith.c b/devtools/gossipwith.c
index c6f427f5..f506787c 100644
--- a/devtools/gossipwith.c
+++ b/devtools/gossipwith.c
@@ -30,6 +30,7 @@ static bool no_init = false;
static bool handle_pings = false;
static bool hex = false;
static bool explicit_network = false;
+static bool no_early_close = false;
static int timeout_after = -1;
static u8 *features;
@@ -154,6 +155,8 @@ static u8 *sync_crypto_read(const tal_t *ctx, int peer_fd, struct crypto_state *
if (!read_all(peer_fd, hdr, sizeof(hdr))) {
status_debug("Failed reading header: %s", strerror(errno));
+ if (no_early_close)
+ exit(1);
exit(0);
}
@@ -237,8 +240,12 @@ static struct io_plan *handshake_success(struct io_conn *conn,
u8 *msg;
if (poll(pollfd, ARRAY_SIZE(pollfd),
- timeout_after < 0 ? -1 : timeout_after * 1000) == 0)
- return 0;
+ timeout_after < 0 ? -1 : timeout_after * 1000) == 0) {
+ /* Timeout */
+ if (no_early_close)
+ exit(1);
+ exit(0);
+ }
/* We always to stdin first if we can */
if (pollfd[0].revents & POLLIN) {
@@ -288,6 +295,8 @@ static struct io_plan *handshake_success(struct io_conn *conn,
err(1, "failed to shutdown write to peer: %s", strerror(errno));
while (sync_crypto_read(NULL, peer_fd, cs));
+ if (max_messages != 0 && no_early_close)
+ exit(1);
exit(0);
}
@@ -368,6 +377,8 @@ int main(int argc, char *argv[])
"Select the network parameters (bitcoin, testnet, signet,"
" regtest, liquid, liquid-regtest, litecoin or"
" litecoin-testnet)");
+ opt_register_noarg("--must-get-max-messages", opt_set_bool, &no_early_close,
+ "Fail with exit code 1 unless we reach maximum messages");
opt_register_noarg("--help|-h", opt_usage_and_exit,
"id@addr[:port] [hex-msg-tosend...]\n"
"Connect to a lightning peer and relay gossip messages from it",
@@ -436,5 +447,6 @@ int main(int argc, char *argv[])
initiator_handshake(conn, &us, &them, &addr, NULL, NORMAL_SOCKET,
handshake_success, argv+2);
- exit(0);
+ /* Unreachable */
+ abort();
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.