aboutsummaryrefslogtreecommitdiff
path: root/migration/channel.c
diff options
context:
space:
mode:
authorAvihai Horon <avihaih@nvidia.com>2023-12-31 11:30:14 +0200
committerPeter Xu <peterx@redhat.com>2024-01-04 09:52:42 +0800
commit4f8cf323e80c17f7d4b5604f1699591326df6262 (patch)
treef2e5593e7dfd4e38c9ffc000a3f69ec436f19285 /migration/channel.c
parent1d3886f837d8e972366a8b58ba8afb0e5efbeed7 (diff)
migration: Fix migration_channel_read_peek() error path
migration_channel_read_peek() calls qio_channel_readv_full() and handles both cases of return value == 0 and return value < 0 the same way, by calling error_setg() with errp. However, if return value < 0, errp is already set, so calling error_setg() with errp will lead to an assert. Fix it by handling these cases separately, calling error_setg() with errp only in return value == 0 case. Fixes: 6720c2b32725 ("migration: check magic value for deciding the mapping of channels") Signed-off-by: Avihai Horon <avihaih@nvidia.com> Reviewed-by: Fabiano Rosas <farosas@suse.de> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Link: https://lore.kernel.org/r/20231231093016.14204-10-avihaih@nvidia.com Signed-off-by: Peter Xu <peterx@redhat.com>
Diffstat (limited to 'migration/channel.c')
-rw-r--r--migration/channel.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/migration/channel.c b/migration/channel.c
index ca3319a309..f9de064f3b 100644
--- a/migration/channel.c
+++ b/migration/channel.c
@@ -117,9 +117,12 @@ int migration_channel_read_peek(QIOChannel *ioc,
len = qio_channel_readv_full(ioc, &iov, 1, NULL, NULL,
QIO_CHANNEL_READ_FLAG_MSG_PEEK, errp);
- if (len <= 0 && len != QIO_CHANNEL_ERR_BLOCK) {
- error_setg(errp,
- "Failed to peek at channel");
+ if (len < 0 && len != QIO_CHANNEL_ERR_BLOCK) {
+ return -1;
+ }
+
+ if (len == 0) {
+ error_setg(errp, "Failed to peek at channel");
return -1;
}