From 70ecd2e64631aa7ad2ca3eebe32bdf19bcbb04a8 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sun, 20 Aug 2023 22:27:16 +0200 Subject: Fail on out-of-memory error --- main.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'main.c') 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) { -- cgit v1.2.3