[PATCH] dbus: don't segfault if p2p isn't enabled

Dan Williams dcbw
Fri Jul 29 12:59:54 PDT 2011


Various pieces of the p2p code assume that p2p is enabled, so make
the D-Bus code not call the p2p stuff if p2p is disabled.  Also
ensures that if p2p is disabled a suitable error is returned to
the D-Bus caller.

Signed-off-by: Dan Williams <dcbw at redhat.com>
---
 wpa_supplicant/dbus/dbus_new_handlers_p2p.c |   42 +++++++++++++++++++++++++++
 1 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
index 2d1540b..0e5fd8c 100644
--- a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
+++ b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
@@ -372,10 +372,34 @@ DBusMessage * wpas_dbus_handler_p2p_disconnect(DBusMessage *message,
 	return NULL;
 }
 
+static dbus_bool_t wpa_dbus_p2p_check_enabled(struct wpa_supplicant *wpa_s,
+					      DBusMessage *message,
+					      DBusMessage **out_reply,
+					      DBusError *error)
+{
+	/* Return an error message or an error if P2P isn't available */
+	if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) {
+		if (out_reply) {
+			*out_reply = dbus_message_new_error(message,
+						DBUS_ERROR_FAILED,
+						"p2p is not available for "
+						"this interface");
+		}
+		dbus_set_error_const(error, DBUS_ERROR_FAILED,
+				"p2p is not available for this interface");
+		return FALSE;
+	}
+	return TRUE;
+}
 
 DBusMessage * wpas_dbus_handler_p2p_flush(DBusMessage *message,
 					  struct wpa_supplicant *wpa_s)
 {
+	DBusMessage *reply = NULL;
+
+	if (!wpa_dbus_p2p_check_enabled(wpa_s, message, &reply, NULL))
+		return reply;
+
 	os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
 	wpa_s->force_long_sd = 0;
 	p2p_flush(wpa_s->global->p2p);
@@ -404,6 +428,9 @@ DBusMessage * wpas_dbus_handler_p2p_connect(DBusMessage *message,
 	char *err_msg = NULL;
 	char *iface = NULL;
 
+	if (!wpa_dbus_p2p_check_enabled(wpa_s, message, &reply, NULL))
+		return reply;
+
 	dbus_message_iter_init(message, &iter);
 
 	if (!wpa_dbus_dict_open_read(&iter, &iter_dict, NULL))
@@ -534,6 +561,9 @@ DBusMessage * wpas_dbus_handler_p2p_invite(DBusMessage *message,
 	int persistent = 0;
 	struct wpa_ssid *ssid;
 
+	if (!wpa_dbus_p2p_check_enabled(wpa_s, message, &reply, NULL))
+		return reply;
+
 	dbus_message_iter_init(message, &iter);
 
 	if (!wpa_dbus_dict_open_read(&iter, &iter_dict, NULL))
@@ -674,6 +704,9 @@ dbus_bool_t wpas_dbus_getter_p2p_device_properties(DBusMessageIter *iter,
 	int i;
 	const struct wpabuf *vendor_ext[P2P_MAX_WPS_VENDOR_EXT];
 
+	if (!wpa_dbus_p2p_check_enabled(wpa_s, NULL, NULL, error))
+		return FALSE;
+
 	if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
 					      "a{sv}", &variant_iter) ||
 	    !wpa_dbus_dict_open_write(&variant_iter, &dict_iter))
@@ -802,6 +835,9 @@ dbus_bool_t wpas_dbus_setter_p2p_device_properties(DBusMessageIter *iter,
 	struct wpa_dbus_dict_entry entry = {.type = DBUS_TYPE_STRING };
 	unsigned int i;
 
+	if (!wpa_dbus_p2p_check_enabled(wpa_s, NULL, NULL, error))
+		return FALSE;
+
 	dbus_message_iter_recurse(iter, &variant_iter);
 	if (!wpa_dbus_dict_open_read(&variant_iter, &iter_dict, error))
 		return FALSE;
@@ -972,6 +1008,9 @@ dbus_bool_t wpas_dbus_getter_p2p_peers(DBusMessageIter *iter, DBusError *error,
 
 	char **peer_obj_paths = NULL;
 
+	if (!wpa_dbus_p2p_check_enabled(wpa_s, NULL, NULL, error))
+		return FALSE;
+
 	dl_list_init(&peer_objpath_list);
 
 	/* Get the first peer info */
@@ -1130,6 +1169,9 @@ dbus_bool_t wpas_dbus_getter_p2p_peer_properties(DBusMessageIter *iter,
 	const struct wpabuf *vendor_extension[P2P_MAX_WPS_VENDOR_EXT];
 	int i, num;
 
+	if (!wpa_dbus_p2p_check_enabled(peer_args->wpa_s, NULL, NULL, error))
+		return FALSE;
+
 	/* get the peer info */
 	info = p2p_get_peer_found(peer_args->wpa_s->global->p2p,
 				  peer_args->p2p_device_addr, 0);
-- 
1.7.6





More information about the Hostap mailing list