@@ -155,9 +155,31 @@ libfsverity_compute_digest(int fd,
struct fsverity_descriptor desc;
struct stat stbuf;
u64 file_size;
- int retval = -EINVAL;
+ int i, retval = -EINVAL;
+
+ if (!digest_ret)
+ return -EINVAL;
+ if (params->version != 1)
+ return -EINVAL;
+ if (!is_power_of_2(params->block_size))
+ return -EINVAL;
+ if (params->salt_size > sizeof(desc.salt)) {
+ error_msg("Salt too long (got %u bytes; max is %zu bytes)",
+ params->salt_size, sizeof(desc.salt));
+ return -EINVAL;
+ }
+ if (params->salt_size && !params->salt)
+ return -EINVAL;
+ for (i = 0;
+ i < sizeof(params->reserved) / sizeof(params->reserved[0]); i++) {
+ if (params->reserved[i])
+ return -EINVAL;
+ }
hash_alg = libfsverity_find_hash_alg_by_num(params->hash_algorithm);
+ if (!hash_alg)
+ return -EINVAL;
+
hash = hash_alg->create_ctx(hash_alg);
digest = malloc(sizeof(struct libfsverity_digest) +
@@ -180,16 +202,9 @@ libfsverity_compute_digest(int fd,
desc.version = 1;
desc.hash_algorithm = params->hash_algorithm;
- ASSERT(is_power_of_2(params->block_size));
desc.log_blocksize = ilog2(params->block_size);
if (params->salt_size != 0) {
- if (params->salt_size > sizeof(desc.salt)) {
- error_msg("Salt too long (got %u bytes; max is %zu bytes)",
- params->salt_size, sizeof(desc.salt));
- retval = EINVAL;
- goto error_out;
- }
memcpy(desc.salt, params->salt, params->salt_size);
desc.salt_size = params->salt_size;
}