fuzz-tests: get rid of magic numbers in `fuzz-hsm_encryption.c`
What changed, and why it matters
This is a minor cleanup change to a fuzz test file. It replaces hard-coded numbers with named constants and swaps a generic memory-free call for a dedicated key-discard function. There is no security vulnerability here.
No action required. This is a benign test-code refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit modifies tests/fuzz/fuzz-hsm_secret.c. It replaces the literal 32 with sizeof(struct secret) and the literal 4294967295 with crypto_pwhash_argon2id_PASSWD_MAX. It also adds mlock_tal_memory(hsm_secret) and replaces tal_free(hsm_secret) with discard_key(hsm_secret). These are readability and test-coverage improvements in test code; no production code is changed.
Changed components
tests/fuzz/fuzz-hsm_secret.cInspect captured patch +6 / −5
diff --git a/tests/fuzz/fuzz-hsm_secret.c b/tests/fuzz/fuzz-hsm_secret.c
index 8c5ccc8..cedaf0d 100644
--- a/tests/fuzz/fuzz-hsm_secret.c
+++ b/tests/fuzz/fuzz-hsm_secret.c
@@ -20,9 +20,9 @@ void init(int *argc, char ***argv)
void run(const uint8_t *data, size_t size)
{
- /* 4294967295 is crypto_pwhash_argon2id_PASSWD_MAX. libfuzzer won't
- * generate inputs that large in practice, but hey. */
- if (size > 32 && size < 4294967295) {
+ /* LibFuzzer won't generate inputs larger than
+ * crypto_pwhash_argon2id_PASSWD_MAX in practice, but hey. */
+ if (size > sizeof(struct secret) && size < crypto_pwhash_argon2id_PASSWD_MAX) {
struct secret *hsm_secret, *encryption_key;
char *passphrase;
u8 encrypted_data[ENCRYPTED_HSM_SECRET_LEN];
@@ -31,8 +31,9 @@ void run(const uint8_t *data, size_t size)
/* Take the first 32 bytes as the plaintext hsm_secret seed,
* and the remaining ones as the passphrase. */
- hsm_secret = (struct secret *)tal_dup_arr(NULL, u8, data, 32, 0);
- passphrase = to_string(NULL, data + 32, size - 32);
+ hsm_secret = (struct secret *)tal_dup_arr(NULL, u8, data, sizeof(struct secret), 0);
+ mlock_tal_memory(hsm_secret);
+ passphrase = to_string(NULL, data + sizeof(struct secret), size - sizeof(struct secret));
/* A valid seed, a valid passphrase. This should not fail. */
encryption_key = get_encryption_key(NULL, passphrase);
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.