[Spice-devel] [PATCH spice-server] red-stream: Handle reading of 0 bytes in red_stream_async_read

Frediano Ziglio fziglio at redhat.com
Tue Jan 30 10:46:39 UTC 2018


ping

> 
> Currently red_stream_async_read cannot handle read of 0 bytes.
> This would cause a wrong assert in async_read_handler.
> Fixing the assert would just make the code wrongly detect a
> disconnection (usually a return of 0 from read is handled that
> way but happens also if you try to read 0 bytes).
> Current callers of these function does not pass 0 as size however
> handling data protocols having data_length+data this can happen
> and is handled manually in red_sasl_handle_auth_steplen.
> Avoid needing manually to check for this condition.
> 
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> ---
>  server/red-stream.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/server/red-stream.c b/server/red-stream.c
> index 8f2c9d32..bdc8bc1f 100644
> --- a/server/red-stream.c
> +++ b/server/red-stream.c
> @@ -550,6 +550,10 @@ void red_stream_async_read(RedStream *stream,
>      AsyncRead *async = &stream->priv->async_read;
>  
>      g_return_if_fail(async->now == NULL && async->end == NULL);
> +    if (size == 0) {
> +        read_done_cb(opaque);
> +        return;
> +    }
>      async->now = data;
>      async->end = async->now + size;
>      async->done = read_done_cb;
> @@ -904,10 +908,6 @@ static void red_sasl_handle_auth_steplen(void *opaque)
>          return red_sasl_async_result(opaque, auth->mechname ?
>          RED_SASL_ERROR_INVALID_DATA : RED_SASL_ERROR_GENERIC);
>      }
>  
> -    if (len == 0) {
> -        return red_sasl_handle_auth_step(auth);
> -    }
> -
>      auth->data = g_realloc(auth->data, len);
>      red_stream_async_read(auth->stream, (uint8_t *)auth->data, len,
>                            red_sasl_handle_auth_step, auth);


More information about the Spice-devel mailing list