diff --git a/usr.sbin/bhyve/qemu_fwcfg.c b/usr.sbin/bhyve/qemu_fwcfg.c --- a/usr.sbin/bhyve/qemu_fwcfg.c +++ b/usr.sbin/bhyve/qemu_fwcfg.c @@ -524,6 +524,7 @@ 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,17 +594,19 @@ 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) { warn("Unable to read file \"%s\"", opt_ptr); free(fwcfg_file->data); close(fd); return (-1); - } else if (fwcfg_file->size < sb.st_size) { + } else if (bytes_read < sb.st_size) { warnx("Only read %u bytes of file \"%s\"", fwcfg_file->size, opt_ptr); } + fwcfg_file->size = bytes_read; + close(fd); } else { qemu_fwcfg_usage(opt);