Skip to content

Commit 6eeb866

Browse files
stevemo-skydioandersson
authored andcommitted
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 <[email protected]> Signed-off-by: Jerry Zhang <[email protected]>
1 parent b4030fa commit 6eeb866

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

vip.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ struct vip_table_generator {
4040
const char *path;
4141
};
4242

43+
void vip_transfer_deinit(struct qdl_device *qdl);
44+
4345
static void print_digest(unsigned char *buf)
4446
{
4547
char hex_str[SHA256_DIGEST_STRING_LENGTH];
@@ -394,17 +396,17 @@ int vip_transfer_init(struct qdl_device *qdl, const char *vip_table_path)
394396
return 0;
395397

396398
out_cleanup:
397-
close(qdl->vip_data.signed_table_fd);
398-
for (size_t i = 0; i < qdl->vip_data.chained_num - 1; ++i)
399-
close(qdl->vip_data.chained_fds[i]);
399+
vip_transfer_deinit(qdl);
400400
return -1;
401401
}
402402

403403
void vip_transfer_deinit(struct qdl_device *qdl)
404404
{
405405
close(qdl->vip_data.signed_table_fd);
406-
for (size_t i = 0; i < qdl->vip_data.chained_num - 1; ++i)
407-
close(qdl->vip_data.chained_fds[i]);
406+
if (qdl->vip_data.chained_num > 0) {
407+
for (size_t i = 0; i < qdl->vip_data.chained_num - 1; ++i)
408+
close(qdl->vip_data.chained_fds[i]);
409+
}
408410
}
409411

410412
static int vip_transfer_send_raw(struct qdl_device *qdl, int table_fd)

0 commit comments

Comments
 (0)