vip: Fix integer underflow in digest count

If no table(s) of digests have been found, we'll hit an
integer underflow while trying to clean up n-1 table
entries. Fix that.

Signed-off-by: Steve Moskovchenko <stevemo@skydio.com>
Signed-off-by: Jerry Zhang <Jerry@skydio.com>
This commit is contained in:
Steve Moskovchenko
2025-12-17 03:50:15 -05:00
committed by Bjorn Andersson
parent b4030fabe6
commit 6eeb866b15

12
vip.c
View File

@@ -40,6 +40,8 @@ struct vip_table_generator {
const char *path;
};
void vip_transfer_deinit(struct qdl_device *qdl);
static void print_digest(unsigned char *buf)
{
char hex_str[SHA256_DIGEST_STRING_LENGTH];
@@ -394,17 +396,17 @@ int vip_transfer_init(struct qdl_device *qdl, const char *vip_table_path)
return 0;
out_cleanup:
close(qdl->vip_data.signed_table_fd);
for (size_t i = 0; i < qdl->vip_data.chained_num - 1; ++i)
close(qdl->vip_data.chained_fds[i]);
vip_transfer_deinit(qdl);
return -1;
}
void vip_transfer_deinit(struct qdl_device *qdl)
{
close(qdl->vip_data.signed_table_fd);
for (size_t i = 0; i < qdl->vip_data.chained_num - 1; ++i)
close(qdl->vip_data.chained_fds[i]);
if (qdl->vip_data.chained_num > 0) {
for (size_t i = 0; i < qdl->vip_data.chained_num - 1; ++i)
close(qdl->vip_data.chained_fds[i]);
}
}
static int vip_transfer_send_raw(struct qdl_device *qdl, int table_fd)