[Spice-devel] [PATCH spice-server v3 10/12] red-stream: Handle properly endianness in SASL code

Snir Sheriber ssheribe at redhat.com
Sun Dec 31 16:15:01 UTC 2017


Hi


On 12/22/2017 12:07 PM, Frediano Ziglio wrote:
> 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 at redhat.com>
> ---
>   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 a0423228f..83afd2b45 100644
> --- a/server/red-stream.c
> +++ b/server/red-stream.c
> @@ -582,6 +582,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));
>   }
>   
> @@ -819,10 +820,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 */
> @@ -867,6 +868,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);
> @@ -939,10 +941,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 */
> @@ -987,6 +989,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);
> @@ -1029,6 +1032,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);
> @@ -1138,7 +1142,7 @@ bool red_sasl_start_auth(RedStream *stream, RedSaslResult result_cb, void *opaqu
>       sasl->mechlist = g_strdup(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;
Looks good to me.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20171231/486d4a54/attachment.html>


More information about the Spice-devel mailing list