diff options
author | Alon Levy <alevy@redhat.com> | 2011-02-03 20:51:01 +0200 |
---|---|---|
committer | Alon Levy <alevy@redhat.com> | 2011-02-07 21:32:40 +0200 |
commit | fe83d01162b3d78192144cdcbf0e21baa0e1e9be (patch) | |
tree | ca01928201124eb839bd47598e7cf62a58937272 /server | |
parent | aed4c72a49feab938fda806e0080b1294ed84487 (diff) | |
download | spice-fe83d01162b3d78192144cdcbf0e21baa0e1e9be.tar.gz spice-fe83d01162b3d78192144cdcbf0e21baa0e1e9be.tar.xz spice-fe83d01162b3d78192144cdcbf0e21baa0e1e9be.zip |
server/smartcard: libcacard uses network byte order, so we must too
Diffstat (limited to 'server')
-rw-r--r-- | server/smartcard.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/server/smartcard.c b/server/smartcard.c index 4dddd944..da678853 100644 --- a/server/smartcard.c +++ b/server/smartcard.c @@ -1,3 +1,5 @@ +#include <arpa/inet.h> + #include "server/char_device.h" #include "server/red_channel.h" #include "server/smartcard.h" @@ -67,6 +69,7 @@ void smartcard_char_device_wakeup(SpiceCharDeviceInstance *sin) VSCMsgHeader *vheader = (VSCMsgHeader*)state->buf; int n; int remaining; + int actual_length; while ((n = sif->read(sin, state->buf_pos, state->buf_size - state->buf_used)) > 0) { state->buf_pos += n; @@ -74,16 +77,17 @@ void smartcard_char_device_wakeup(SpiceCharDeviceInstance *sin) if (state->buf_used < sizeof(VSCMsgHeader)) { continue; } - if (vheader->length > state->buf_size) { - state->buf_size = MAX(state->buf_size*2, vheader->length + sizeof(VSCMsgHeader)); + actual_length = ntohl(vheader->length); + if (actual_length > state->buf_size) { + state->buf_size = MAX(state->buf_size*2, actual_length + sizeof(VSCMsgHeader)); state->buf = spice_realloc(state->buf, state->buf_size); ASSERT(state->buf != NULL); } - if (state->buf_used - sizeof(VSCMsgHeader) < vheader->length) { + if (state->buf_used - sizeof(VSCMsgHeader) < actual_length) { continue; } smartcard_char_device_on_message_from_device(state, vheader); - remaining = state->buf_used - sizeof(VSCMsgHeader) > vheader->length; + remaining = state->buf_used - sizeof(VSCMsgHeader) > actual_length; if (remaining > 0) { memcpy(state->buf, state->buf_pos, remaining); } @@ -98,6 +102,10 @@ void smartcard_char_device_on_message_from_device( { VSCMsgHeader *sent_header; + vheader->type = ntohl(vheader->type); + vheader->length = ntohl(vheader->length); + vheader->reader_id = ntohl(vheader->reader_id); + switch (vheader->type) { case VSC_Init: return; @@ -401,15 +409,20 @@ static void smartcard_channel_write_to_reader( SpiceCharDeviceInstance *sin; SpiceCharDeviceInterface *sif; uint32_t n; + uint32_t actual_length = vheader->length; ASSERT(vheader->reader_id >= 0 && vheader->reader_id <= g_smartcard_readers.num); sin = g_smartcard_readers.sin[vheader->reader_id]; sif = SPICE_CONTAINEROF(sin->base.sif, SpiceCharDeviceInterface, base); + /* protocol requires messages to be in network endianess */ + vheader->type = htonl(vheader->type); + vheader->length = htonl(vheader->length); + vheader->reader_id = htonl(vheader->reader_id); n = sif->write(sin, (uint8_t*)vheader, - vheader->length + sizeof(VSCMsgHeader)); + actual_length + sizeof(VSCMsgHeader)); // TODO - add ring - ASSERT(n == vheader->length + sizeof(VSCMsgHeader)); + ASSERT(n == actual_length + sizeof(VSCMsgHeader)); } static int smartcard_channel_handle_message(RedChannel *channel, SpiceDataHeader *header, uint8_t *msg) |