mirror of
https://github.com/vanhoefm/fragattacks.git
synced 2024-11-25 08:48:31 -05:00
dbus: Fix wpa_supplicant_add_iface() calls
Removed the hack that used typecast to get rid of const by using local variables that are allocated and freed. Fix couple of memory leaks and check that the required Ifname parameter is included.
This commit is contained in:
parent
a646086d51
commit
2f00ad446e
@ -75,15 +75,6 @@ DBusMessage * wpas_dbus_new_success_reply(DBusMessage *message)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void wpas_dbus_free_wpa_interface(struct wpa_interface *iface)
|
|
||||||
{
|
|
||||||
os_free((char *) iface->driver);
|
|
||||||
os_free((char *) iface->driver_param);
|
|
||||||
os_free((char *) iface->confname);
|
|
||||||
os_free((char *) iface->bridge_ifname);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wpas_dbus_global_add_interface - Request registration of a network interface
|
* wpas_dbus_global_add_interface - Request registration of a network interface
|
||||||
* @message: Pointer to incoming dbus message
|
* @message: Pointer to incoming dbus message
|
||||||
@ -98,13 +89,14 @@ static void wpas_dbus_free_wpa_interface(struct wpa_interface *iface)
|
|||||||
DBusMessage * wpas_dbus_global_add_interface(DBusMessage *message,
|
DBusMessage * wpas_dbus_global_add_interface(DBusMessage *message,
|
||||||
struct wpa_global *global)
|
struct wpa_global *global)
|
||||||
{
|
{
|
||||||
struct wpa_interface iface;
|
|
||||||
char *ifname = NULL;
|
char *ifname = NULL;
|
||||||
|
char *driver = NULL;
|
||||||
|
char *driver_param = NULL;
|
||||||
|
char *confname = NULL;
|
||||||
|
char *bridge_ifname = NULL;
|
||||||
DBusMessage *reply = NULL;
|
DBusMessage *reply = NULL;
|
||||||
DBusMessageIter iter;
|
DBusMessageIter iter;
|
||||||
|
|
||||||
os_memset(&iface, 0, sizeof(iface));
|
|
||||||
|
|
||||||
dbus_message_iter_init(message, &iter);
|
dbus_message_iter_init(message, &iter);
|
||||||
|
|
||||||
/* First argument: interface name (DBUS_TYPE_STRING)
|
/* First argument: interface name (DBUS_TYPE_STRING)
|
||||||
@ -115,7 +107,6 @@ DBusMessage * wpas_dbus_global_add_interface(DBusMessage *message,
|
|||||||
dbus_message_iter_get_basic(&iter, &ifname);
|
dbus_message_iter_get_basic(&iter, &ifname);
|
||||||
if (!os_strlen(ifname))
|
if (!os_strlen(ifname))
|
||||||
goto error;
|
goto error;
|
||||||
iface.ifname = ifname;
|
|
||||||
|
|
||||||
/* Second argument: dict of options */
|
/* Second argument: dict of options */
|
||||||
if (dbus_message_iter_next(&iter)) {
|
if (dbus_message_iter_next(&iter)) {
|
||||||
@ -129,31 +120,32 @@ DBusMessage * wpas_dbus_global_add_interface(DBusMessage *message,
|
|||||||
goto error;
|
goto error;
|
||||||
if (!strcmp(entry.key, "driver") &&
|
if (!strcmp(entry.key, "driver") &&
|
||||||
(entry.type == DBUS_TYPE_STRING)) {
|
(entry.type == DBUS_TYPE_STRING)) {
|
||||||
iface.driver = os_strdup(entry.str_value);
|
driver = os_strdup(entry.str_value);
|
||||||
if (iface.driver == NULL)
|
wpa_dbus_dict_entry_clear(&entry);
|
||||||
|
if (driver == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
} else if (!strcmp(entry.key, "driver-params") &&
|
} else if (!strcmp(entry.key, "driver-params") &&
|
||||||
(entry.type == DBUS_TYPE_STRING)) {
|
(entry.type == DBUS_TYPE_STRING)) {
|
||||||
iface.driver_param =
|
driver_param = os_strdup(entry.str_value);
|
||||||
os_strdup(entry.str_value);
|
wpa_dbus_dict_entry_clear(&entry);
|
||||||
if (iface.driver_param == NULL)
|
if (driver_param == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
} else if (!strcmp(entry.key, "config-file") &&
|
} else if (!strcmp(entry.key, "config-file") &&
|
||||||
(entry.type == DBUS_TYPE_STRING)) {
|
(entry.type == DBUS_TYPE_STRING)) {
|
||||||
iface.confname = os_strdup(entry.str_value);
|
confname = os_strdup(entry.str_value);
|
||||||
if (iface.confname == NULL)
|
wpa_dbus_dict_entry_clear(&entry);
|
||||||
|
if (confname == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
} else if (!strcmp(entry.key, "bridge-ifname") &&
|
} else if (!strcmp(entry.key, "bridge-ifname") &&
|
||||||
(entry.type == DBUS_TYPE_STRING)) {
|
(entry.type == DBUS_TYPE_STRING)) {
|
||||||
iface.bridge_ifname =
|
bridge_ifname = os_strdup(entry.str_value);
|
||||||
os_strdup(entry.str_value);
|
wpa_dbus_dict_entry_clear(&entry);
|
||||||
if (iface.bridge_ifname == NULL)
|
if (bridge_ifname == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
} else {
|
} else {
|
||||||
wpa_dbus_dict_entry_clear(&entry);
|
wpa_dbus_dict_entry_clear(&entry);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
wpa_dbus_dict_entry_clear(&entry);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,13 +153,20 @@ DBusMessage * wpas_dbus_global_add_interface(DBusMessage *message,
|
|||||||
* Try to get the wpa_supplicant record for this iface, return
|
* Try to get the wpa_supplicant record for this iface, return
|
||||||
* an error if we already control it.
|
* an error if we already control it.
|
||||||
*/
|
*/
|
||||||
if (wpa_supplicant_get_iface(global, iface.ifname) != NULL) {
|
if (wpa_supplicant_get_iface(global, ifname) != NULL) {
|
||||||
reply = dbus_message_new_error(message,
|
reply = dbus_message_new_error(message,
|
||||||
WPAS_ERROR_EXISTS_ERROR,
|
WPAS_ERROR_EXISTS_ERROR,
|
||||||
"wpa_supplicant already "
|
"wpa_supplicant already "
|
||||||
"controls this interface.");
|
"controls this interface.");
|
||||||
} else {
|
} else {
|
||||||
struct wpa_supplicant *wpa_s;
|
struct wpa_supplicant *wpa_s;
|
||||||
|
struct wpa_interface iface;
|
||||||
|
os_memset(&iface, 0, sizeof(iface));
|
||||||
|
iface.ifname = ifname;
|
||||||
|
iface.driver = driver;
|
||||||
|
iface.driver_param = driver_param;
|
||||||
|
iface.confname = confname;
|
||||||
|
iface.bridge_ifname = bridge_ifname;
|
||||||
/* Otherwise, have wpa_supplicant attach to it. */
|
/* Otherwise, have wpa_supplicant attach to it. */
|
||||||
if ((wpa_s = wpa_supplicant_add_iface(global, &iface))) {
|
if ((wpa_s = wpa_supplicant_add_iface(global, &iface))) {
|
||||||
const char *path = wpa_supplicant_get_dbus_path(wpa_s);
|
const char *path = wpa_supplicant_get_dbus_path(wpa_s);
|
||||||
@ -182,12 +181,17 @@ DBusMessage * wpas_dbus_global_add_interface(DBusMessage *message,
|
|||||||
"interface.");
|
"interface.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wpas_dbus_free_wpa_interface(&iface);
|
|
||||||
|
out:
|
||||||
|
os_free(driver);
|
||||||
|
os_free(driver_param);
|
||||||
|
os_free(confname);
|
||||||
|
os_free(bridge_ifname);
|
||||||
return reply;
|
return reply;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
wpas_dbus_free_wpa_interface(&iface);
|
reply = wpas_dbus_new_invalid_opts_error(message, NULL);
|
||||||
return wpas_dbus_new_invalid_opts_error(message, NULL);
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -167,15 +167,6 @@ DBusMessage * wpas_dbus_error_invald_args(DBusMessage *message,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void free_wpa_interface(struct wpa_interface *iface)
|
|
||||||
{
|
|
||||||
os_free((char *) iface->driver);
|
|
||||||
os_free((char *) iface->driver_param);
|
|
||||||
os_free((char *) iface->confname);
|
|
||||||
os_free((char *) iface->bridge_ifname);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static const char *dont_quote[] = {
|
static const char *dont_quote[] = {
|
||||||
"key_mgmt", "proto", "pairwise", "auth_alg", "group", "eap",
|
"key_mgmt", "proto", "pairwise", "auth_alg", "group", "eap",
|
||||||
"opensc_engine_path", "pkcs11_engine_path", "pkcs11_module_path",
|
"opensc_engine_path", "pkcs11_engine_path", "pkcs11_module_path",
|
||||||
@ -351,20 +342,20 @@ out:
|
|||||||
* Returns: The object path of the new interface object,
|
* Returns: The object path of the new interface object,
|
||||||
* or a dbus error message with more information
|
* or a dbus error message with more information
|
||||||
*
|
*
|
||||||
* Handler function for "addInterface" method call. Handles requests
|
* Handler function for "CreateInterface" method call. Handles requests
|
||||||
* by dbus clients to register a network interface that wpa_supplicant
|
* by dbus clients to register a network interface that wpa_supplicant
|
||||||
* will manage.
|
* will manage.
|
||||||
*/
|
*/
|
||||||
DBusMessage * wpas_dbus_handler_create_interface(DBusMessage *message,
|
DBusMessage * wpas_dbus_handler_create_interface(DBusMessage *message,
|
||||||
struct wpa_global *global)
|
struct wpa_global *global)
|
||||||
{
|
{
|
||||||
struct wpa_interface iface;
|
|
||||||
DBusMessageIter iter_dict;
|
DBusMessageIter iter_dict;
|
||||||
DBusMessage *reply = NULL;
|
DBusMessage *reply = NULL;
|
||||||
DBusMessageIter iter;
|
DBusMessageIter iter;
|
||||||
struct wpa_dbus_dict_entry entry;
|
struct wpa_dbus_dict_entry entry;
|
||||||
|
char *driver = NULL;
|
||||||
os_memset(&iface, 0, sizeof(iface));
|
char *ifname = NULL;
|
||||||
|
char *bridge_ifname = NULL;
|
||||||
|
|
||||||
dbus_message_iter_init(message, &iter);
|
dbus_message_iter_init(message, &iter);
|
||||||
|
|
||||||
@ -375,37 +366,47 @@ DBusMessage * wpas_dbus_handler_create_interface(DBusMessage *message,
|
|||||||
goto error;
|
goto error;
|
||||||
if (!strcmp(entry.key, "Driver") &&
|
if (!strcmp(entry.key, "Driver") &&
|
||||||
(entry.type == DBUS_TYPE_STRING)) {
|
(entry.type == DBUS_TYPE_STRING)) {
|
||||||
iface.driver = os_strdup(entry.str_value);
|
driver = os_strdup(entry.str_value);
|
||||||
if (iface.driver == NULL)
|
wpa_dbus_dict_entry_clear(&entry);
|
||||||
|
if (driver == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
} else if (!strcmp(entry.key, "Ifname") &&
|
} else if (!strcmp(entry.key, "Ifname") &&
|
||||||
(entry.type == DBUS_TYPE_STRING)) {
|
(entry.type == DBUS_TYPE_STRING)) {
|
||||||
iface.ifname = os_strdup(entry.str_value);
|
ifname = os_strdup(entry.str_value);
|
||||||
if (iface.ifname == NULL)
|
wpa_dbus_dict_entry_clear(&entry);
|
||||||
|
if (ifname == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
} else if (!strcmp(entry.key, "BridgeIfname") &&
|
} else if (!strcmp(entry.key, "BridgeIfname") &&
|
||||||
(entry.type == DBUS_TYPE_STRING)) {
|
(entry.type == DBUS_TYPE_STRING)) {
|
||||||
iface.bridge_ifname = os_strdup(entry.str_value);
|
bridge_ifname = os_strdup(entry.str_value);
|
||||||
if (iface.bridge_ifname == NULL)
|
wpa_dbus_dict_entry_clear(&entry);
|
||||||
|
if (bridge_ifname == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
} else {
|
} else {
|
||||||
wpa_dbus_dict_entry_clear(&entry);
|
wpa_dbus_dict_entry_clear(&entry);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
wpa_dbus_dict_entry_clear(&entry);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ifname == NULL)
|
||||||
|
goto error; /* Required Ifname argument missing */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Try to get the wpa_supplicant record for this iface, return
|
* Try to get the wpa_supplicant record for this iface, return
|
||||||
* an error if we already control it.
|
* an error if we already control it.
|
||||||
*/
|
*/
|
||||||
if (wpa_supplicant_get_iface(global, iface.ifname) != NULL) {
|
if (wpa_supplicant_get_iface(global, ifname) != NULL) {
|
||||||
reply = dbus_message_new_error(message,
|
reply = dbus_message_new_error(message,
|
||||||
WPAS_DBUS_ERROR_IFACE_EXISTS,
|
WPAS_DBUS_ERROR_IFACE_EXISTS,
|
||||||
"wpa_supplicant already "
|
"wpa_supplicant already "
|
||||||
"controls this interface.");
|
"controls this interface.");
|
||||||
} else {
|
} else {
|
||||||
struct wpa_supplicant *wpa_s;
|
struct wpa_supplicant *wpa_s;
|
||||||
|
struct wpa_interface iface;
|
||||||
|
os_memset(&iface, 0, sizeof(iface));
|
||||||
|
iface.driver = driver;
|
||||||
|
iface.ifname = ifname;
|
||||||
|
iface.bridge_ifname = bridge_ifname;
|
||||||
/* Otherwise, have wpa_supplicant attach to it. */
|
/* Otherwise, have wpa_supplicant attach to it. */
|
||||||
if ((wpa_s = wpa_supplicant_add_iface(global, &iface))) {
|
if ((wpa_s = wpa_supplicant_add_iface(global, &iface))) {
|
||||||
const char *path = wpas_dbus_get_path(wpa_s);
|
const char *path = wpas_dbus_get_path(wpa_s);
|
||||||
@ -418,12 +419,16 @@ DBusMessage * wpas_dbus_handler_create_interface(DBusMessage *message,
|
|||||||
"interface.");
|
"interface.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free_wpa_interface(&iface);
|
|
||||||
|
out:
|
||||||
|
os_free(driver);
|
||||||
|
os_free(ifname);
|
||||||
|
os_free(bridge_ifname);
|
||||||
return reply;
|
return reply;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
free_wpa_interface(&iface);
|
reply = wpas_dbus_error_invald_args(message, NULL);
|
||||||
return wpas_dbus_error_invald_args(message, NULL);
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user