aboutsummaryrefslogtreecommitdiffstats
path: root/librecrypt_add_algorithm.c
diff options
context:
space:
mode:
authorMattias Andrée <m@maandree.se>2026-05-15 20:53:25 +0200
committerMattias Andrée <m@maandree.se>2026-05-15 20:53:25 +0200
commit193d39d9b78a9e3c0c257b2e1e9f9dd4a7a13349 (patch)
treec3b4eaf8df53babc7e37df4384d1be3be1cd9186 /librecrypt_add_algorithm.c
parentFix some minor issues (diff)
downloadlibrecrypt-193d39d9b78a9e3c0c257b2e1e9f9dd4a7a13349.tar.gz
librecrypt-193d39d9b78a9e3c0c257b2e1e9f9dd4a7a13349.tar.bz2
librecrypt-193d39d9b78a9e3c0c257b2e1e9f9dd4a7a13349.tar.xz
Misc
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'librecrypt_add_algorithm.c')
-rw-r--r--librecrypt_add_algorithm.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/librecrypt_add_algorithm.c b/librecrypt_add_algorithm.c
index 4c6520e..ad21ec4 100644
--- a/librecrypt_add_algorithm.c
+++ b/librecrypt_add_algorithm.c
@@ -62,6 +62,8 @@ librecrypt_add_algorithm(char *out_buffer, size_t size, const char *augend, cons
r_int = snprintf(out_buffer, size + 1u, "*%zu", hashsize2);
if (r_int < 2)
abort(); /* $covered$ (impossible reliably) */
+ if (ret > SIZE_MAX - (size_t)r_int)
+ abort(); /* $covered$ (impossible) */
ret += (size_t)r_int;
} else {
out_buffer[0u] = '\0';
@@ -79,11 +81,19 @@ librecrypt_add_algorithm(char *out_buffer, size_t size, const char *augend, cons
r_int = snprintf(NULL, 0u, "*%zu", hashsize2);
if (r_int < 2)
abort(); /* $covered$ (impossible reliably) */
+ if (ret > SIZE_MAX - (size_t)r_int)
+ abort(); /* $covered$ (impossible) */
ret += (size_t)r_int;
out:
if (nul_term)
out_buffer[0u] = '\0';
}
+ if (ret > (size_t)SSIZE_MAX) {
+ /* $covered{$ (manually) */
+ errno = EOVERFLOW;
+ return -1;
+ /* $covered}$ */
+ }
return (ssize_t)ret;
}
@@ -96,7 +106,9 @@ librecrypt_add_algorithm(char *out_buffer, size_t size, const char *augend, cons
r_int = 0;
}
- /* Measure `augent` and '>' in output */
+ /* Measure `augend` and '>' in output */
+ if (prefix1 > SIZE_MAX - 1u - (size_t)r_int)
+ abort(); /* $covered$ (impossible) */
ret = prefix1 + (size_t)r_int + 1u;
/* Decode the hash from base-64 to binary */
@@ -160,6 +172,14 @@ librecrypt_add_algorithm(char *out_buffer, size_t size, const char *augend, cons
abort(); /* $covered$ (impossible) */
return -1;
}
+ if (ret > (size_t)(SSIZE_MAX - r)) {
+ /* $covered{$ (manually) */
+ librecrypt_wipe(phrase, phraselen);
+ free(phrase);
+ errno = EOVERFLOW;
+ return -1;
+ /* $covered}$ */
+ }
ret += (size_t)r;
librecrypt_wipe(phrase, phraselen);