[ovs-dev] [PATCH 6/6] netdev: Fix null pointer dereference reported by clang.

Ben Pfaff blp at ovn.org
Wed Jul 12 04:19:40 UTC 2017


On Mon, Jun 19, 2017 at 07:54:04PM +0100, Bhanuprakash Bodireddy wrote:
> Clang reports that array access from 'dumps' variable result in null pointer
> dereference.
> 
> Signed-off-by: Bhanuprakash Bodireddy <bhanuprakash.bodireddy at intel.com>
> ---
>  lib/netdev.c | 16 +++++++++-------
>  1 file changed, 9 insertions(+), 7 deletions(-)
> 
> diff --git a/lib/netdev.c b/lib/netdev.c
> index 001b7b3..336c141 100644
> --- a/lib/netdev.c
> +++ b/lib/netdev.c
> @@ -2290,14 +2290,16 @@ netdev_ports_flow_dump_create(const void *obj, int *ports)
>  
>      dumps = count ? xzalloc(sizeof *dumps * count) : NULL;
>  
> -    HMAP_FOR_EACH(data, node, &port_to_netdev) {
> -        if (data->obj == obj) {
> -            if (netdev_flow_dump_create(data->netdev, &dumps[i])) {
> -                continue;
> -            }
> +    if (dumps) {
> +        HMAP_FOR_EACH(data, node, &port_to_netdev) {
> +            if (data->obj == obj) {
> +                if (netdev_flow_dump_create(data->netdev, &dumps[i])) {
> +                    continue;
> +                }
>  
> -            dumps[i]->port = data->dpif_port.port_no;
> -            i++;
> +                dumps[i]->port = data->dpif_port.port_no;
> +                i++;
> +            }

I think that, if 'dumps' is null, the code that uses it will never be
reached, because we already saw in the previous loop through the hmap
that the 'if' condition is never true, so I don't think that this change
is needed.


More information about the dev mailing list