Blame SOURCES/0002-channel-main-Check-proper-size-and-caps-handling-VD_.patch

be82ae
From 5324e83bf636b995522088d508e61ba5543777f4 Mon Sep 17 00:00:00 2001
be82ae
From: Frediano Ziglio <fziglio@redhat.com>
be82ae
Date: Thu, 19 Mar 2020 06:07:39 +0000
be82ae
Subject: [PATCH 2/9] channel-main: Check proper size and caps handling
be82ae
 VD_AGENT_FILE_XFER_STATUS_NOT_ENOUGH_SPACE
be82ae
be82ae
VDAgentFileXferStatusMessage message can or cannot contain detailed
be82ae
information attached to it.
be82ae
Detect this correctly checking capabilities and flags.
be82ae
This fixes a small buffer overflow reading in case the details are
be82ae
off the payload.
be82ae
be82ae
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
be82ae
Acked-by: Victor Toso <victortoso@redhat.com>
be82ae
(cherry picked from commit b13fd0664075c951f5418f5828c0803408ad664d)
be82ae
---
be82ae
 meson.build        |  2 +-
be82ae
 src/channel-main.c | 16 +++++++++++++---
be82ae
 2 files changed, 14 insertions(+), 4 deletions(-)
be82ae
be82ae
diff --git a/meson.build b/meson.build
be82ae
index 995268b..8098989 100644
be82ae
--- a/meson.build
be82ae
+++ b/meson.build
be82ae
@@ -81,7 +81,7 @@ endforeach
be82ae
 #
be82ae
 # check for mandatory dependencies
be82ae
 #
be82ae
-spice_protocol_version='>= 0.14.1'
be82ae
+spice_protocol_version='>= 0.14.2'
be82ae
 
be82ae
 glib_version = '2.46'
be82ae
 glib_version_info = '>= @0@'.format(glib_version)
be82ae
diff --git a/src/channel-main.c b/src/channel-main.c
be82ae
index e89b813..c4fe02b 100644
be82ae
--- a/src/channel-main.c
be82ae
+++ b/src/channel-main.c
be82ae
@@ -1891,6 +1891,7 @@ static void file_xfer_read_async_cb(GObject *source_object,
be82ae
 
be82ae
 /* coroutine context */
be82ae
 static void main_agent_handle_xfer_status(SpiceMainChannel *channel,
be82ae
+                                          const VDAgentMessage *msg_hdr,
be82ae
                                           VDAgentFileXferStatusMessage *msg)
be82ae
 {
be82ae
     SpiceFileTransferTask *xfer_task;
be82ae
@@ -1917,8 +1918,17 @@ static void main_agent_handle_xfer_status(SpiceMainChannel *channel,
be82ae
                                     _("The spice agent reported an error during the file transfer"));
be82ae
         break;
be82ae
     case VD_AGENT_FILE_XFER_STATUS_NOT_ENOUGH_SPACE: {
be82ae
-        uint64_t *free_space = SPICE_ALIGNED_CAST(uint64_t *, msg->data);
be82ae
-        gchar *free_space_str = g_format_size(*free_space);
be82ae
+        const VDAgentFileXferStatusNotEnoughSpace *err =
be82ae
+            (VDAgentFileXferStatusNotEnoughSpace*) msg->data;
be82ae
+        if (!test_agent_cap(channel, VD_AGENT_CAP_FILE_XFER_DETAILED_ERRORS) ||
be82ae
+            msg_hdr->size < sizeof(*msg) + sizeof(*err)) {
be82ae
+            error =
be82ae
+                g_error_new(SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED,
be82ae
+                            _("File transfer failed due to lack of free space on remote machine"));
be82ae
+            break;
be82ae
+        }
be82ae
+
be82ae
+        gchar *free_space_str = g_format_size(err->disk_free_space);
be82ae
         gchar *file_size_str = g_format_size(spice_file_transfer_task_get_total_bytes(xfer_task));
be82ae
         error = g_error_new(SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED,
be82ae
                             _("File transfer failed due to lack of free space on remote machine "
be82ae
@@ -2110,7 +2120,7 @@ static void main_agent_handle_msg(SpiceChannel *channel,
be82ae
         break;
be82ae
     }
be82ae
     case VD_AGENT_FILE_XFER_STATUS:
be82ae
-        main_agent_handle_xfer_status(self, payload);
be82ae
+        main_agent_handle_xfer_status(self, msg, payload);
be82ae
         break;
be82ae
     default:
be82ae
         g_warning("unhandled agent message type: %u (%s), size %u",
be82ae
-- 
be82ae
2.26.2
be82ae