[Spice-devel] [PATCH spice-server] char-device: Fix some endianess issues migrating

Frediano Ziglio fziglio at redhat.com
Wed Sep 18 08:03:27 UTC 2019


Data from network are always little endian, convert to host
convention.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/char-device.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/server/char-device.c b/server/char-device.c
index 03ac9907..e7c6dfa8 100644
--- a/server/char-device.c
+++ b/server/char-device.c
@@ -855,7 +855,7 @@ void red_char_device_migrate_data_marshall_empty(SpiceMarshaller *m)
     mig_data = (SpiceMigrateDataCharDevice *)spice_marshaller_reserve_space(m,
                                                                             sizeof(*mig_data));
     memset(mig_data, 0, sizeof(*mig_data));
-    mig_data->version = SPICE_MIGRATE_DATA_CHAR_DEVICE_VERSION;
+    mig_data->version = GUINT32_TO_LE(SPICE_MIGRATE_DATA_CHAR_DEVICE_VERSION);
     mig_data->connected = FALSE;
 }
 
@@ -926,14 +926,23 @@ void red_char_device_migrate_data_marshall(RedCharDevice *dev,
 }
 
 bool red_char_device_restore(RedCharDevice *dev,
-                             SpiceMigrateDataCharDevice *mig_data)
+                             SpiceMigrateDataCharDevice *mig_data_le)
 {
     RedCharDeviceClient *dev_client;
     uint32_t client_tokens_window;
+    SpiceMigrateDataCharDevice mig_data[1];
 
     spice_assert(g_list_length(dev->priv->clients) == 1 &&
                  dev->priv->wait_for_migrate_data);
 
+    mig_data->version = GUINT32_FROM_LE(mig_data_le->version);
+    mig_data->connected = mig_data_le->connected;
+    mig_data->num_client_tokens = GUINT32_FROM_LE(mig_data_le->num_client_tokens);
+    mig_data->num_send_tokens = GUINT32_FROM_LE(mig_data_le->num_send_tokens);
+    mig_data->write_size = GUINT32_FROM_LE(mig_data_le->write_size);
+    mig_data->write_num_client_tokens = GUINT32_FROM_LE(mig_data_le->write_num_client_tokens);
+    mig_data->write_data_ptr = GUINT32_FROM_LE(mig_data_le->write_data_ptr);
+
     dev_client = g_list_last(dev->priv->clients)->data;
     if (mig_data->version > SPICE_MIGRATE_DATA_CHAR_DEVICE_VERSION) {
         spice_error("dev %p error: migration data version %u is bigger than self %u",
-- 
2.21.0



More information about the Spice-devel mailing list