[Spice-devel,1/8] server/smartcard: fix smartcard_channel_send_error

Submitted by Christophe Fergeau on Aug. 17, 2011, 6:25 p.m.

Details

Message ID 1313580353-3086-2-git-send-email-cfergeau@redhat.com
State New, archived
Headers show

Not browsing as part of any series.

Commit Message

Christophe Fergeau Aug. 17, 2011, 6:25 p.m.
From: Alon Levy <alevy@redhat.com>

It was sending the wrong data, the memory right after the VCSMsgHeader
which was actually not where the data was.

Fixed by having the header and data (VSCError, 4 bytes of the error code)
embedded in the ErrorItem pipe item.
---
 server/smartcard.c |   30 +++++++-----------------------
 1 files changed, 7 insertions(+), 23 deletions(-)

Patch hide | download patch | download mbox

diff --git a/server/smartcard.c b/server/smartcard.c
index c75094d..8919400 100644
--- a/server/smartcard.c
+++ b/server/smartcard.c
@@ -41,8 +41,8 @@  enum {
 
 typedef struct ErrorItem {
     PipeItem base;
-    uint32_t reader_id;
-    uint32_t error;
+    VSCMsgHeader vheader;
+    VSCMsgError  error;
 } ErrorItem;
 
 typedef struct MsgItem {
@@ -288,23 +288,6 @@  static void smartcard_channel_send_data(RedChannel *channel, PipeItem *item, VSC
     red_channel_begin_send_message(channel);
 }
 
-static void smartcard_channel_send_message(RedChannel *channel, PipeItem *item,
-    uint32_t reader_id, VSCMsgType type, uint8_t* data, uint32_t len)
-{
-    VSCMsgHeader mhHeader;
-    //SpiceMarshaller* m = msg->marshaller();
-
-    mhHeader.type = type;
-    mhHeader.length = len;
-    mhHeader.reader_id = reader_id;
-    //_marshallers->msg_SpiceMsgData(m, &msgdata);
-    //spice_marshaller_add(m, (uint8_t*)&mhHeader, sizeof(mhHeader));
-    //spice_marshaller_add(m, data, len);
-    //marshaller_outgoing_write(msg);
-
-    smartcard_channel_send_data(channel, item, &mhHeader);
-}
-
 static void smartcard_channel_send_error(
     SmartCardChannel *smartcard_channel, PipeItem *item)
 {
@@ -312,8 +295,7 @@  static void smartcard_channel_send_error(
     VSCMsgError error;
 
     error.code = error_item->error;
-    smartcard_channel_send_message(&smartcard_channel->base, item, error_item->reader_id,
-        VSC_Error, (uint8_t*)&error, sizeof(error));
+    smartcard_channel_send_data(&smartcard_channel->base, item, &error_item->vheader);
 }
 
 static void smartcard_channel_send_msg(
@@ -367,8 +349,10 @@  static void smartcard_push_error(SmartCardChannel* channel, uint32_t reader_id,
     ErrorItem *error_item = spice_new0(ErrorItem, 1);
 
     error_item->base.type = PIPE_ITEM_TYPE_ERROR;
-    error_item->reader_id = reader_id;
-    error_item->error = error;
+    error_item->vheader.reader_id = reader_id;
+    error_item->vheader.type = VSC_Error;
+    error_item->vheader.length = sizeof(error_item->error);
+    error_item->error.code = error;
     smartcard_channel_pipe_add(channel, &error_item->base);
 }