mirror of
				https://git.kernel.org/pub/scm/network/wireless/iwd.git
				synced 2025-11-04 00:37:22 +01:00 
			
		
		
		
	All the watchlist notify macros were broken in that they did not check that the watchlist item was still valid before calling it. This only came into play when a watchlist was being notified and one of the notify functions removed an item from the same watchlist. It appears this was already thought of since watchlist_remove checks 'in_notify' and will mark the item's id as stale (0), but that id never got checked in the notify macros. This fixes testAdHoc valgrind warning: ==3347== Invalid read of size 4 ==3347== at 0x416612: eapol_rx_auth_packet (eapol.c:1871) ==3347== by 0x416DD4: __eapol_rx_packet (eapol.c:2334) ==3347== by 0x40725B: netdev_pae_read (netdev.c:3515) ==3347== by 0x440958: io_callback (io.c:123) ==3347== by 0x43FDED: l_main_iterate (main.c:376) ==3347== by 0x43FEAB: l_main_run (main.c:423) ==3347== by 0x40377A: main (main.c:489) ...
		
			
				
	
	
		
			117 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			117 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
/*
 | 
						|
 *
 | 
						|
 *  Wireless daemon for Linux
 | 
						|
 *
 | 
						|
 *  Copyright (C) 2016-2017  Intel Corporation. All rights reserved.
 | 
						|
 *
 | 
						|
 *  This library is free software; you can redistribute it and/or
 | 
						|
 *  modify it under the terms of the GNU Lesser General Public
 | 
						|
 *  License as published by the Free Software Foundation; either
 | 
						|
 *  version 2.1 of the License, or (at your option) any later version.
 | 
						|
 *
 | 
						|
 *  This library is distributed in the hope that it will be useful,
 | 
						|
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
						|
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 | 
						|
 *  Lesser General Public License for more details.
 | 
						|
 *
 | 
						|
 *  You should have received a copy of the GNU Lesser General Public
 | 
						|
 *  License along with this library; if not, write to the Free Software
 | 
						|
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 | 
						|
 *
 | 
						|
 */
 | 
						|
 | 
						|
typedef void (*watchlist_item_destroy_func_t)(void *data);
 | 
						|
 | 
						|
struct watchlist_item {
 | 
						|
	unsigned int id;
 | 
						|
	void *notify;
 | 
						|
	void *notify_data;
 | 
						|
	watchlist_item_destroy_func_t destroy;
 | 
						|
};
 | 
						|
 | 
						|
struct watchlist_ops {
 | 
						|
	void (*item_free)(struct watchlist_item *item);
 | 
						|
};
 | 
						|
 | 
						|
struct watchlist {
 | 
						|
	int next_id;
 | 
						|
	struct l_queue *items;
 | 
						|
	bool in_notify : 1;
 | 
						|
	bool stale_items : 1;
 | 
						|
	const struct watchlist_ops *ops;
 | 
						|
};
 | 
						|
 | 
						|
struct watchlist *watchlist_new(const struct watchlist_ops *ops);
 | 
						|
void watchlist_init(struct watchlist *watchlist,
 | 
						|
					const struct watchlist_ops *ops);
 | 
						|
unsigned int watchlist_add(struct watchlist *watchlist, void *notify,
 | 
						|
					void *notify_data,
 | 
						|
					watchlist_item_destroy_func_t destroy);
 | 
						|
unsigned int watchlist_link(struct watchlist *watchlist,
 | 
						|
					struct watchlist_item *item,
 | 
						|
					void *notify, void *notify_data,
 | 
						|
					watchlist_item_destroy_func_t destroy);
 | 
						|
bool watchlist_remove(struct watchlist *watchlist, unsigned int id);
 | 
						|
void watchlist_destroy(struct watchlist *watchlist);
 | 
						|
void watchlist_free(struct watchlist *watchlist);
 | 
						|
 | 
						|
void __watchlist_prune_stale(struct watchlist *watchlist);
 | 
						|
 | 
						|
#define WATCHLIST_NOTIFY(watchlist, type, args...)			\
 | 
						|
	do {								\
 | 
						|
		const struct l_queue_entry *entry =			\
 | 
						|
				l_queue_get_entries((watchlist)->items);\
 | 
						|
									\
 | 
						|
		(watchlist)->in_notify = true;				\
 | 
						|
		for (; entry; entry = entry->next) {			\
 | 
						|
			struct watchlist_item *item = entry->data;	\
 | 
						|
			type t = item->notify;				\
 | 
						|
			if (item->id == 0)				\
 | 
						|
				continue;				\
 | 
						|
			t(args, item->notify_data);			\
 | 
						|
		}							\
 | 
						|
		(watchlist)->in_notify = false;				\
 | 
						|
		if ((watchlist)->stale_items)				\
 | 
						|
			__watchlist_prune_stale(watchlist);		\
 | 
						|
	} while	(false)							\
 | 
						|
 | 
						|
#define WATCHLIST_NOTIFY_MATCHES(watchlist, match, match_data, type, args...) \
 | 
						|
	do {								\
 | 
						|
		const struct l_queue_entry *entry =			\
 | 
						|
				l_queue_get_entries((watchlist)->items);\
 | 
						|
									\
 | 
						|
		(watchlist)->in_notify = true;				\
 | 
						|
		for (; entry; entry = entry->next) {			\
 | 
						|
			struct watchlist_item *item = entry->data;	\
 | 
						|
			type t = item->notify;				\
 | 
						|
									\
 | 
						|
			if (item->id == 0)				\
 | 
						|
				continue;				\
 | 
						|
			if (!match(item, match_data))			\
 | 
						|
				continue;				\
 | 
						|
									\
 | 
						|
			t(args, item->notify_data);			\
 | 
						|
		}							\
 | 
						|
		(watchlist)->in_notify = false;				\
 | 
						|
		if ((watchlist)->stale_items)				\
 | 
						|
			__watchlist_prune_stale(watchlist);		\
 | 
						|
	} while	(false)
 | 
						|
 | 
						|
#define WATCHLIST_NOTIFY_NO_ARGS(watchlist, type)			\
 | 
						|
	do {								\
 | 
						|
		const struct l_queue_entry *entry =			\
 | 
						|
				l_queue_get_entries((watchlist)->items);\
 | 
						|
									\
 | 
						|
		(watchlist)->in_notify = true;				\
 | 
						|
		for (; entry; entry = entry->next) {			\
 | 
						|
			struct watchlist_item *item = entry->data;	\
 | 
						|
			type t = item->notify;				\
 | 
						|
			if (item->id == 0)				\
 | 
						|
				continue;				\
 | 
						|
			t(item->notify_data);			\
 | 
						|
		}							\
 | 
						|
		(watchlist)->in_notify = false;				\
 | 
						|
		if ((watchlist)->stale_items)				\
 | 
						|
			__watchlist_prune_stale(watchlist);		\
 | 
						|
	} while	(false)
 |