Skip to content

Commit

Permalink
pytest: fix hsmtool which reports leak under address sanitizer.
Browse files Browse the repository at this point in the history
Couldn't figure out why hsmtool.proc.wait(WAIT_TIMEOUT) returns 1?
hsmtool doesn't ever seem to exit status 1!

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Nov 17, 2024
1 parent 0741d4d commit 9af01b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 6 additions & 1 deletion tests/test_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,12 @@ def test_hsmtool_generatehsm(node_factory):
"cake have wedding\n".encode("utf-8"))
hsmtool.wait_for_log(r"Enter your passphrase:")
write_all(master_fd, "This is actually not a passphrase\n".encode("utf-8"))
assert hsmtool.proc.wait(WAIT_TIMEOUT) == 0
if hsmtool.proc.wait(WAIT_TIMEOUT) != 0:
hsmtool.logs_catchup()
print("hsmtool failure! Logs:")
for l in hsmtool.logs:
print(' ' + l)
assert False
hsmtool.is_in_log(r"New hsm_secret file created")

# Check should pass.
Expand Down
8 changes: 5 additions & 3 deletions tools/hsmtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ static char *read_mnemonic(void) {

static int generate_hsm(const char *hsm_secret_path,
const char *lang_id,
const char *mnemonic,
char *mnemonic,
char *passphrase)
{
const char *err;
Expand Down Expand Up @@ -584,6 +584,7 @@ static int generate_hsm(const char *hsm_secret_path,
printf("New hsm_secret file created at %s\n", hsm_secret_path);
printf("Use the `encrypt` command to encrypt the BIP32 seed if needed\n");

free(mnemonic);
free(passphrase);
return 0;
}
Expand Down Expand Up @@ -685,6 +686,7 @@ static int check_hsm(const char *hsm_secret_path)

printf("OK\n");

free(mnemonic);
free(passphrase);
return 0;
}
Expand Down Expand Up @@ -810,8 +812,8 @@ int main(int argc, char *argv[])
if (lang_id && !check_lang(lang_id))
show_usage(argv[0]);

word_list = (argc > 4 ? argv[4] : NULL);
/* generate_hsm expects to free this, so use strdup */
/* generate_hsm expects to free these, so use strdup */
word_list = (argc > 4 ? strdup(argv[4]) : NULL);
passphrase = (argc > 5 ? strdup(argv[5]) : NULL);

return generate_hsm(hsm_secret_path, lang_id, word_list, passphrase);
Expand Down

0 comments on commit 9af01b0

Please sign in to comment.