hsm_secret: fixup! make read_line tidier
What changed, and why it matters
This is a tiny code cleanup change in a helper function that reads a line of text. It replaces a manual check for a trailing newline with a utility function called strends(), and adjusts how the string length is tracked. There is no security-relevant change: the behavior is equivalent and no bug is being fixed.
No security action needed. Treat as normal code maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
In common/hsm_secret.c, read_line() is refactored to use strends(line, “\n”) instead of an explicit strlen/char comparison to detect a trailing newline. When present, the newline is no longer overwritten with ‘\0’; instead the length is simply decremented before calling tal_strndup(). This is a stylistic/readability fixup with identical functional outcome.
Changed components
common/hsm_secret.cread_line()Inspect captured patch +2 / −2
diff --git a/common/hsm_secret.c b/common/hsm_secret.c
index 9acb044f..bcb8cf4a 100644
--- a/common/hsm_secret.c
+++ b/common/hsm_secret.c
@@ -415,8 +415,8 @@ static char *read_line(const tal_t *ctx)
/* Strip newline */
size_t len = strlen(line);
- if (len > 0 && line[len - 1] == '\n')
- line[len - 1] = '\0';
+ if (strends(line, "\n"))
+ len--;
/* Convert to tal string */
char *result = tal_strndup(ctx, line, len);
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.