qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] linux-user: Check sscanf return value in open_n


From: Philippe Mathieu-Daudé
Subject: Re: [Qemu-devel] [PATCH] linux-user: Check sscanf return value in open_net_route()
Date: Tue, 5 Feb 2019 21:26:48 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0

On 2/5/19 6:42 PM, Peter Maydell wrote:
> Coverity warns (CID 1390634) that open_net_route() is not
> checking the return value from sscanf(), which means that
> it might then use values that aren't initialized.
> 
> Errors here should in general not happen since we're passing
> an assumed-good /proc/net/route from the host kernel, but
> if we do fail to parse a line then just skip it in the output
> we pass to the guest.
> 
> Signed-off-by: Peter Maydell <address@hidden>

Reviewed-by: Philippe Mathieu-Daudé <address@hidden>

> ---
>  linux-user/syscall.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index b5786d4fc1f..894678aa8b4 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -6762,9 +6762,15 @@ static int open_net_route(void *cpu_env, int fd)
>          char iface[16];
>          uint32_t dest, gw, mask;
>          unsigned int flags, refcnt, use, metric, mtu, window, irtt;
> -        sscanf(line, "%s\t%08x\t%08x\t%04x\t%d\t%d\t%d\t%08x\t%d\t%u\t%u\n",
> -                     iface, &dest, &gw, &flags, &refcnt, &use, &metric,
> -                     &mask, &mtu, &window, &irtt);
> +        int fields;
> +
> +        fields = sscanf(line,
> +                        
> "%s\t%08x\t%08x\t%04x\t%d\t%d\t%d\t%08x\t%d\t%u\t%u\n",
> +                        iface, &dest, &gw, &flags, &refcnt, &use, &metric,
> +                        &mask, &mtu, &window, &irtt);
> +        if (fields != 11) {
> +            continue;
> +        }
>          dprintf(fd, "%s\t%08x\t%08x\t%04x\t%d\t%d\t%d\t%08x\t%d\t%u\t%u\n",
>                  iface, tswap32(dest), tswap32(gw), flags, refcnt, use,
>                  metric, tswap32(mask), mtu, window, irtt);
> 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]