fuzz-tests: Get rid of magic numbers
What changed, and why it matters
This commit only cleans up a fuzz test file by replacing hard-coded numbers (36 and 32) with size-of expressions. It does not change any runtime behavior or fix a security bug.
No action needed; this is a non-security refactoring change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies tests/fuzz/fuzz-channel_id.c to use sizeof(outpoint) and sizeof(chan_id) instead of literal constants 36 and 32. The values are identical, so the compiled code is unchanged. It is a code-quality/refactoring change in test infrastructure only.
Changed components
tests/fuzz/fuzz-channel_id.cInspect captured patch +4 / −5
diff --git a/tests/fuzz/fuzz-channel_id.c b/tests/fuzz/fuzz-channel_id.c
index 6f7eb68d..df3d35e4 100644
--- a/tests/fuzz/fuzz-channel_id.c
+++ b/tests/fuzz/fuzz-channel_id.c
@@ -23,14 +23,13 @@ void run(const uint8_t *data, size_t size)
size_t wire_max;
uint8_t *wire_buf;
- /* 32 (txid) + 4 (vout) */
- if (size < 36)
+ if (size < sizeof(outpoint))
return;
- v1_chunks = get_chunks(NULL, data, size, 36);
+ v1_chunks = get_chunks(NULL, data, size, sizeof(outpoint));
for (size_t i = 0; i < tal_count(v1_chunks); i++) {
wire_ptr = v1_chunks[i];
- wire_max = 36;
+ wire_max = sizeof(outpoint);
fromwire_bitcoin_outpoint(&wire_ptr, &wire_max, &outpoint);
assert(wire_ptr);
derive_channel_id(&chan_id, &outpoint);
@@ -54,7 +53,7 @@ void run(const uint8_t *data, size_t size)
}
tal_free(v2_chunks);
- marshal_chunks = get_chunks(NULL, data, size, 32);
+ marshal_chunks = get_chunks(NULL, data, size, sizeof(chan_id));
for (size_t i = 0; i < tal_count(marshal_chunks); i++) {
wire_ptr = marshal_chunks[i];
wire_max = tal_count(marshal_chunks[i]);
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.