bhyve: fix buffer overflow in QemuFwCfg

We're accessing one element of the newly allocated and the old directory
too much.

Reported by:		andy@omniosce.org
Reviewed by:		markj
Fixes:			6f9ebb3d0f ("bhyve: add helper for adding fwcfg files")
MFC after:		1 week
Differential Revision:	https://reviews.freebsd.org/D42220
This commit is contained in:
Corvin Köhne 2023-10-16 10:52:21 +02:00
parent d8735eb7ac
commit 4a3810075f
No known key found for this signature in database
GPG key ID: D854DA56315E026A

View file

@ -365,7 +365,7 @@ qemu_fwcfg_add_file(const char *name, const uint32_t size, void *const data)
/* copy files above file_index to directory */
memcpy(&new_directory->files[file_index + 1],
&fwcfg_sc.directory->files[file_index],
(count - file_index) * sizeof(struct qemu_fwcfg_file));
(count - file_index - 1) * sizeof(struct qemu_fwcfg_file));
/* free old directory */
free(fwcfg_sc.directory);