[Spice-devel] [spice-gtk v2] channel-usbredir: avoid calling memcpy() will NULL src

Frediano Ziglio fziglio at redhat.com
Thu Mar 1 07:21:58 UTC 2018


> 
> From: Victor Toso <me at victortoso.com>
> 
> Code built with address sanitizer has runtime error:
>  > channel-usbredir.c:642:5: runtime error: null pointer passed
>  > as argument 2, which is declared to never be null
> 
> Signed-off-by: Victor Toso <victortoso at redhat.com>

Acked-by: Frediano Ziglio <fziglio at redhat.com>

> ---
>  src/channel-usbredir.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/src/channel-usbredir.c b/src/channel-usbredir.c
> index 1f791bc..928b22a 100644
> --- a/src/channel-usbredir.c
> +++ b/src/channel-usbredir.c
> @@ -635,11 +635,10 @@ static int usbredir_read_callback(void *user_data,
> uint8_t *data, int count)
>      SpiceUsbredirChannel *channel = user_data;
>      SpiceUsbredirChannelPrivate *priv = channel->priv;
>  
> -    if (priv->read_buf_size < count) {
> -        count = priv->read_buf_size;
> -    }
> +    count = MIN(priv->read_buf_size, count);
>  
> -    memcpy(data, priv->read_buf, count);
> +    if (count != 0)
> +        memcpy(data, priv->read_buf, count);
>  
>      priv->read_buf_size -= count;
>      if (priv->read_buf_size) {

Bracket, or not bracket, that is the Question :-)

Frediano


More information about the Spice-devel mailing list