aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2023-08-20 22:27:16 +0200
committerThomas Voss <mail@thomasvoss.com> 2023-08-20 22:27:16 +0200
commit70ecd2e64631aa7ad2ca3eebe32bdf19bcbb04a8 (patch)
treed338099c6f653af8ff5adf54b663b0c50905f488 /main.c
parent71f22e1ac610de3507bea726ae0d0db4c59e732d (diff)
Fail on out-of-memory error
Diffstat (limited to 'main.c')
-rw-r--r--main.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/main.c b/main.c
index de87cab..185a5cc 100644
--- a/main.c
+++ b/main.c
@@ -203,14 +203,16 @@ totp(struct totp_config conf, uint32_t *code)
clean = false;
} else {
enc_sec_len += 8 - enc_sec_len % 8;
- enc_sec = malloc(enc_sec_len);
+ if ((enc_sec = malloc(enc_sec_len)) == NULL)
+ err(EXIT_FAILURE, "malloc");
memcpy(enc_sec, conf.enc_sec, old);
memset(enc_sec + old, '=', enc_sec_len - old);
clean = true;
}
- keylen = old * 5 / 8;
- key = calloc(keylen, sizeof(char));
+ keylen = old / 1.6;
+ if ((key = calloc(keylen + 1, sizeof(char))) == NULL)
+ err(EXIT_FAILURE, "calloc");
b32toa(key, enc_sec, enc_sec_len);
if (time(&epoch) == (time_t)-1) {