bhyve: error out if fwcfg user file isn't read completely
At the moment, fwcfg reads the file once at startup and passes these
data to the guest. Therefore, we should always read the whole file.
Otherwise we should error out.
Additionally, GCC12 complains that the comparison whether
fwcfg_file->size is lower than 0 is always false due to the limited
range of data type.
Reviewed by: markj
Fixes: ca14781c81
("bhyve: add cmdline option for user defined fw_cfg items")
MFC after: 1 week
Sponsored by: Beckhoff Automation GmbH & Co. KG
Differential Revision: https://reviews.freebsd.org/D40076
This commit is contained in:
parent
bdd4717752
commit
26d9f973d8
@ -524,6 +524,7 @@ qemu_fwcfg_parse_cmdline_arg(const char *opt)
|
||||
struct qemu_fwcfg_user_file *fwcfg_file;
|
||||
struct stat sb;
|
||||
const char *opt_ptr, *opt_end;
|
||||
ssize_t bytes_read;
|
||||
int fd;
|
||||
|
||||
fwcfg_file = malloc(sizeof(*fwcfg_file));
|
||||
@ -593,16 +594,14 @@ qemu_fwcfg_parse_cmdline_arg(const char *opt)
|
||||
close(fd);
|
||||
return (ENOMEM);
|
||||
}
|
||||
fwcfg_file->size = read(fd, fwcfg_file->data, sb.st_size);
|
||||
if ((ssize_t)fwcfg_file->size < 0) {
|
||||
bytes_read = read(fd, fwcfg_file->data, sb.st_size);
|
||||
if (bytes_read < 0 || bytes_read != sb.st_size) {
|
||||
warn("Unable to read file \"%s\"", opt_ptr);
|
||||
free(fwcfg_file->data);
|
||||
close(fd);
|
||||
return (-1);
|
||||
} else if (fwcfg_file->size < sb.st_size) {
|
||||
warnx("Only read %u bytes of file \"%s\"",
|
||||
fwcfg_file->size, opt_ptr);
|
||||
}
|
||||
fwcfg_file->size = bytes_read;
|
||||
|
||||
close(fd);
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user