aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2020-06-14 23:18:44 -0700
committerEric Biggers <ebiggers@google.com>2020-06-14 23:18:44 -0700
commit1addf09d33fd028f5746cd151d385b10efa3993e (patch)
treeba26bd9349b743fc12daea86f971f7054c965f5a
parentd705f9860c99d8d569c5e5399648358ba7c9358b (diff)
downloadfsverity-utils-1addf09d33fd028f5746cd151d385b10efa3993e.tar.gz
lib/compute_digest: check that the block size isn't too small
Signed-off-by: Eric Biggers <ebiggers@google.com>
-rw-r--r--lib/compute_digest.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/compute_digest.c b/lib/compute_digest.c
index 52566a8..85de28e 100644
--- a/lib/compute_digest.c
+++ b/lib/compute_digest.c
@@ -185,7 +185,7 @@ libfsverity_compute_digest(void *fd, libfsverity_read_fn_t read_fn,
params->salt_size);
return -EINVAL;
}
- if (params->salt_size && !params->salt) {
+ if (params->salt_size && !params->salt) {
libfsverity_error_msg("salt_size specified, but salt is NULL");
return -EINVAL;
}
@@ -204,6 +204,12 @@ libfsverity_compute_digest(void *fd, libfsverity_read_fn_t read_fn,
return -EINVAL;
}
+ if (params->block_size < 2 * hash_alg->digest_size) {
+ libfsverity_error_msg("block size (%u) too small for hash algorithm %s",
+ params->block_size, hash_alg->name);
+ return -EINVAL;
+ }
+
hash = hash_alg->create_ctx(hash_alg);
if (!hash)
return -ENOMEM;