From 52b3268b78346abe7781c984018558f312aa59d8 Mon Sep 17 00:00:00 2001 From: Andrew Zaborowski Date: Tue, 15 Jan 2019 07:34:05 +0100 Subject: [PATCH] netdev: Allow NULL prefix in netdev_frame_watch_add Make sure we don't pass NULLs to memcmp or l_memdup when the prefix buffer is NULL. There's no point having callers pass dummy buffers if they need to watch frames independent of the frame data. --- src/netdev.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/netdev.c b/src/netdev.c index 6449143c..4a8fb4a6 100644 --- a/src/netdev.c +++ b/src/netdev.c @@ -3676,7 +3676,8 @@ static bool netdev_frame_watch_match_prefix(const void *a, const void *b) return fw->frame_type == info->frame_type && fw->prefix_len <= info->body_len && - !memcmp(fw->prefix, info->body, fw->prefix_len); + (fw->prefix_len == 0 || + !memcmp(fw->prefix, info->body, fw->prefix_len)); } static void netdev_mgmt_frame_event(struct l_genl_msg *msg, @@ -4594,7 +4595,7 @@ uint32_t netdev_frame_watch_add(struct netdev *netdev, uint16_t frame_type, fw = l_new(struct netdev_frame_watch, 1); fw->frame_type = frame_type; - fw->prefix = l_memdup(prefix, prefix_len); + fw->prefix = prefix_len ? l_memdup(prefix, prefix_len) : NULL; fw->prefix_len = prefix_len; id = watchlist_link(&netdev->frame_watches, &fw->super, handler, user_data, NULL);