diff options
author | Thomas Voss <mail@thomasvoss.com> | 2023-08-20 22:27:16 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2023-08-20 22:27:16 +0200 |
commit | 70ecd2e64631aa7ad2ca3eebe32bdf19bcbb04a8 (patch) | |
tree | d338099c6f653af8ff5adf54b663b0c50905f488 /main.c | |
parent | 71f22e1ac610de3507bea726ae0d0db4c59e732d (diff) |
Fail on out-of-memory error
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -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) { |