All SPICE protocol is little endian, there's no agreement on other endian and currently we support only little endian so make sure this will work even possibly running on a big endian machine. Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx> --- server/red-stream.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/server/red-stream.c b/server/red-stream.c index c548d9916..1fd310080 100644 --- a/server/red-stream.c +++ b/server/red-stream.c @@ -580,6 +580,7 @@ static bool red_stream_write_u8(RedStream *s, uint8_t n) static bool red_stream_write_u32(RedStream *s, uint32_t n) { + n = GUINT32_TO_LE(n); return red_stream_write_all(s, &n, sizeof(uint32_t)); } @@ -817,10 +818,10 @@ static void red_sasl_handle_auth_step(void *opaque) if (serveroutlen) { serveroutlen += 1; - red_stream_write_all(stream, &serveroutlen, sizeof(uint32_t)); + red_stream_write_u32(stream, serveroutlen); red_stream_write_all(stream, serverout, serveroutlen); } else { - red_stream_write_all(stream, &serveroutlen, sizeof(uint32_t)); + red_stream_write_u32(stream, serveroutlen); } /* Whether auth is complete */ @@ -865,6 +866,7 @@ static void red_sasl_handle_auth_steplen(void *opaque) RedStream *stream = ((RedSASLAuth *)opaque)->stream; RedSASL *sasl = &stream->priv->sasl; + sasl->len = GUINT32_FROM_LE(sasl->len); spice_debug("Got steplen %d", sasl->len); if (sasl->len > SASL_DATA_MAX_LEN) { spice_warning("Too much SASL data %d", sasl->len); @@ -937,10 +939,10 @@ static void red_sasl_handle_auth_start(void *opaque) if (serveroutlen) { serveroutlen += 1; - red_stream_write_all(stream, &serveroutlen, sizeof(uint32_t)); + red_stream_write_u32(stream, serveroutlen); red_stream_write_all(stream, serverout, serveroutlen); } else { - red_stream_write_all(stream, &serveroutlen, sizeof(uint32_t)); + red_stream_write_u32(stream, serveroutlen); } /* Whether auth is complete */ @@ -985,6 +987,7 @@ static void red_sasl_handle_auth_startlen(void *opaque) RedStream *stream = ((RedSASLAuth *)opaque)->stream; RedSASL *sasl = &stream->priv->sasl; + sasl->len = GUINT32_FROM_LE(sasl->len); spice_debug("Got client start len %d", sasl->len); if (sasl->len > SASL_DATA_MAX_LEN) { spice_warning("Too much SASL data %d", sasl->len); @@ -1027,6 +1030,7 @@ static void red_sasl_handle_auth_mechlen(void *opaque) RedStream *stream = ((RedSASLAuth *)opaque)->stream; RedSASL *sasl = &stream->priv->sasl; + sasl->len = GUINT32_FROM_LE(sasl->len); if (sasl->len < 1 || sasl->len > SASL_MAX_MECHNAME_LEN) { spice_warning("Got bad client mechname len %d", sasl->len); return red_sasl_async_result(opaque, RED_SASL_ERROR_INVALID_DATA); @@ -1136,7 +1140,7 @@ bool red_sasl_start_auth(RedStream *stream, RedSaslResult result_cb, void *opaqu sasl->mechlist = mechlist; mechlistlen = strlen(mechlist); - if (!red_stream_write_all(stream, &mechlistlen, sizeof(uint32_t)) + if (!red_stream_write_u32(stream, mechlistlen) || !red_stream_write_all(stream, sasl->mechlist, mechlistlen)) { spice_warning("SASL mechanisms write error"); goto error; -- 2.14.3 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel