Browse Source

qemu-file: qemu_file_get_fd(): fail if no expected fd come

In _put() we don't actually allow send a service byte
without fd. So on _get() it's unexpected. Let's be strict.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
Link: https://lore.kernel.org/qemu-devel/20260114064710.176268-3-vsementsov@yandex-team.ru
Signed-off-by: Fabiano Rosas <farosas@suse.de>
pull/316/head
Vladimir Sementsov-Ogievskiy 7 months ago
committed by Fabiano Rosas
parent
commit
030baed787
  1. 26
      migration/qemu-file.c

26
migration/qemu-file.c

@ -389,28 +389,34 @@ int qemu_file_get_fd(QEMUFile *f)
{ {
int fd = -1; int fd = -1;
FdEntry *fde; FdEntry *fde;
Error *err = NULL;
if (!f->can_pass_fd) { if (!f->can_pass_fd) {
Error *err = NULL;
error_setg(&err, "%s does not support fd passing", f->ioc->name); error_setg(&err, "%s does not support fd passing", f->ioc->name);
error_report_err(error_copy(err)); goto fail;
qemu_file_set_error_obj(f, -EIO, err);
goto out;
} }
/* Force the dummy byte and its fd passenger to appear. */ /* Force the dummy byte and its fd passenger to appear. */
qemu_peek_byte(f, 0); qemu_peek_byte(f, 0);
fde = QTAILQ_FIRST(&f->fds); fde = QTAILQ_FIRST(&f->fds);
if (fde) { if (!fde) {
qemu_get_byte(f); /* Drop the dummy byte */ error_setg(&err, "%s no FD come with service byte", f->ioc->name);
fd = fde->fd; goto fail;
QTAILQ_REMOVE(&f->fds, fde, entry);
g_free(fde);
} }
out:
qemu_get_byte(f); /* Drop the dummy byte */
fd = fde->fd;
QTAILQ_REMOVE(&f->fds, fde, entry);
g_free(fde);
trace_qemu_file_get_fd(f->ioc->name, fd); trace_qemu_file_get_fd(f->ioc->name, fd);
return fd; return fd;
fail:
error_report_err(error_copy(err));
qemu_file_set_error_obj(f, -EIO, err);
return -1;
} }
/** Closes the file /** Closes the file

Loading…
Cancel
Save