[ovs-dev] [PATCH 09/11] tnl-neigh-cache: Fix possible null pointer.

Ben Pfaff blp at ovn.org
Mon Oct 30 19:35:51 UTC 2017


On Sat, Oct 28, 2017 at 10:31:56AM -0700, William Tu wrote:
> Clang reports possible null pointer '&wc->masks.ipv6_src' to memset.
> Workaround it by adding extra pointer check.
> 
> Signed-off-by: William Tu <u9012063 at gmail.com>
> ---
>  lib/tnl-neigh-cache.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/lib/tnl-neigh-cache.c b/lib/tnl-neigh-cache.c
> index a28ce1de8855..b3024848b8d5 100644
> --- a/lib/tnl-neigh-cache.c
> +++ b/lib/tnl-neigh-cache.c
> @@ -178,6 +178,9 @@ tnl_nd_snoop(const struct flow *flow, struct flow_wildcards *wc,
>          return EINVAL;
>      }
>  
> +    if (OVS_UNLIKELY(!wc))
> +        return EINVAL;
> +
>      memset(&wc->masks.ipv6_src, 0xff, sizeof wc->masks.ipv6_src);
>      memset(&wc->masks.ipv6_dst, 0xff, sizeof wc->masks.ipv6_dst);
>      memset(&wc->masks.nd_target, 0xff, sizeof wc->masks.nd_target);

Thanks for taking a look at this.

In practice, I believe that there is no bug because this function is
currently always called with nonnull 'wc'.  If it were to be called with
a null 'wc', however, we'd still want the function to do its work
instead of aborting.  So I think that the correct change would be to
surround the memsets with "if (wc) { ... }";

(In addition, OVS coding style calls for {} around conditional
statements.)

Thanks,

Ben.


More information about the dev mailing list