From 87e8c2862c00571cede9bbcb5fa51f5a77e6e0b8 Mon Sep 17 00:00:00 2001 From: Lucas Date: Tue, 16 Feb 2021 17:01:25 +0000 Subject: [PATCH] cli.c: rename key{,len} -> secret{,len} and free after use --- cli.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/cli.c b/cli.c index a367457..024f240 100644 --- a/cli.c +++ b/cli.c @@ -42,7 +42,7 @@ int main(int argc, char *argv[]) { const char *errstr; - unsigned char *key; + unsigned char *secret; char *in, *line; struct otpcfg otpcfg; size_t inlen, linesz; @@ -50,7 +50,7 @@ main(int argc, char *argv[]) uint64_t counter; unsigned int period; int32_t r; - int ch, digits, do_hotp, do_totp, keylen; + int ch, digits, do_hotp, do_totp, secretlen; enum otp_hmac hmac; counter = (uint64_t)time(NULL); @@ -124,19 +124,19 @@ main(int argc, char *argv[]) inlen = linelen; } - keylen = b32_decoded_len(in, inlen); - if (keylen == -1) + secretlen = b32_decoded_len(in, inlen); + if (secretlen == -1) errx(1, "invalid base32 string: %s", in); - key = malloc(keylen); - if (key == NULL) + secret = malloc(secretlen); + if (secret == NULL) err(1, "malloc"); - if (!b32_decode(key, keylen, in, inlen)) + if (!b32_decode(secret, secretlen, in, inlen)) errx(1, "error decoding base32 string"); otpcfg.algorithm = hmac; otpcfg.digits = digits; - otpcfg.secret = key; - otpcfg.secretlen = keylen; + otpcfg.secret = secret; + otpcfg.secretlen = secretlen; if (do_hotp) { otpcfg.type = OTP_HOTP; otpcfg.u.hotp.counter = counter; @@ -147,6 +147,7 @@ main(int argc, char *argv[]) } r = otp(&otpcfg); + free(secret); if (r == -1) errx(1, "couldn't calculate %cOTP", do_hotp ? 'H' : 'T'); printf("%0*" PRId32 "\n", digits, r);