[Spice-devel] [PATCH spice-server] reds: Check link header magic without waiting for the whole header

Christophe Fergeau cfergeau at redhat.com
Tue Feb 28 12:10:16 UTC 2017


Hey,

On Tue, Feb 28, 2017 at 10:58:47AM +0000, Frediano Ziglio wrote:
> This allows the connection to early fail in case initial bytes
> are not correct.
> This allows for instance VNC client to graceful fail connecting
> to a spice-server. This happens easily as the two protocols
> share the same range of ports.
> 
> This resolves rhbz#1416692.
> 
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> Tested-by: Daniel P. Berrange <berrange at redhat.com>
> Acked-by: Uri Lublin <uril at redhat.com>

This looks good to me, though I would not keep the Tested-by/Acked-by
that were there on the previous patch.

Acked-by: Christophe Fergeau <cfergeau at redhat.com>

> ---
>  server/reds.c | 28 ++++++++++++++++++++--------
>  1 file changed, 20 insertions(+), 8 deletions(-)
> 
> This patch is for 0.12 branch, backported from master.
> 
> diff --git a/server/reds.c b/server/reds.c
> index 9150454..f439a36 100644
> --- a/server/reds.c
> +++ b/server/reds.c
> @@ -2192,12 +2192,6 @@ static void reds_handle_read_header_done(void *opaque)
>      header->minor_version = GUINT32_FROM_LE(header->minor_version);
>      header->size = GUINT32_FROM_LE(header->size);
>  
> -    if (header->magic != SPICE_MAGIC) {
> -        reds_send_link_error(link, SPICE_LINK_ERR_INVALID_MAGIC);
> -        reds_link_free(link);
> -        return;
> -    }
> -
>      if (header->major_version != SPICE_VERSION_MAJOR) {
>          if (header->major_version > 0) {
>              reds_send_link_error(link, SPICE_LINK_ERR_VERSION_MISMATCH);
> @@ -2227,13 +2221,31 @@ static void reds_handle_read_header_done(void *opaque)
>                             link);
>  }
>  
> +static void reds_handle_read_magic_done(void *opaque)
> +{
> +    RedLinkInfo *link = (RedLinkInfo *)opaque;
> +    const SpiceLinkHeader *header = &link->link_header;
> +
> +    if (header->magic != SPICE_MAGIC) {
> +        reds_send_link_error(link, SPICE_LINK_ERR_INVALID_MAGIC);
> +        reds_link_free(link);
> +        return;
> +    }
> +
> +    reds_stream_async_read(link->stream,
> +                           ((uint8_t *)&link->link_header) + sizeof(header->magic),
> +                           sizeof(SpiceLinkHeader) - sizeof(header->magic),
> +                           reds_handle_read_header_done,
> +                           link);
> +}
> +
>  static void reds_handle_new_link(RedLinkInfo *link)
>  {
>      reds_stream_set_async_error_handler(link->stream, reds_handle_link_error);
>      reds_stream_async_read(link->stream,
>                             (uint8_t *)&link->link_header,
> -                           sizeof(SpiceLinkHeader),
> -                           reds_handle_read_header_done,
> +                           sizeof(link->link_header.magic),
> +                           reds_handle_read_magic_done,
>                             link);
>  }
>  
> -- 
> 2.9.3
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20170228/32dc8477/attachment.sig>


More information about the Spice-devel mailing list