mirror of
https://github.com/vanhoefm/fragattacks.git
synced 2025-01-18 10:54:03 -05:00
dbus: Get rid of unnecessary string duplication in dbus_path
There is no point in making it so complex to initialize a string with two allocations and a function call.
This commit is contained in:
parent
52bdd880a3
commit
1912049828
@ -28,24 +28,6 @@
|
|||||||
#include "dbus_common.h"
|
#include "dbus_common.h"
|
||||||
#include "dbus_common_i.h"
|
#include "dbus_common_i.h"
|
||||||
|
|
||||||
/**
|
|
||||||
* wpas_dbus_set_path - Assign a dbus path to an interface
|
|
||||||
* @wpa_s: wpa_supplicant interface structure
|
|
||||||
* @path: dbus path to set on the interface
|
|
||||||
* Returns: 0 on success, -1 on error
|
|
||||||
*/
|
|
||||||
static int wpas_dbus_set_path(struct wpa_supplicant *wpa_s,
|
|
||||||
const char *path)
|
|
||||||
{
|
|
||||||
u32 len = os_strlen(path);
|
|
||||||
if (len >= WPAS_DBUS_OBJECT_PATH_MAX)
|
|
||||||
return -1;
|
|
||||||
if (wpa_s->dbus_new_path)
|
|
||||||
return -1;
|
|
||||||
wpa_s->dbus_new_path = os_strdup(path);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wpas_dbus_signal_interface - Send a interface related event signal
|
* wpas_dbus_signal_interface - Send a interface related event signal
|
||||||
@ -1766,7 +1748,6 @@ int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s)
|
|||||||
{
|
{
|
||||||
|
|
||||||
struct wpa_dbus_object_desc *obj_desc = NULL;
|
struct wpa_dbus_object_desc *obj_desc = NULL;
|
||||||
char *path;
|
|
||||||
struct wpas_dbus_priv *ctrl_iface = wpa_s->global->dbus;
|
struct wpas_dbus_priv *ctrl_iface = wpa_s->global->dbus;
|
||||||
int next;
|
int next;
|
||||||
|
|
||||||
@ -1775,19 +1756,13 @@ int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* Create and set the interface's object path */
|
/* Create and set the interface's object path */
|
||||||
path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
|
wpa_s->dbus_new_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
|
||||||
if (path == NULL)
|
if (wpa_s->dbus_new_path == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
next = ctrl_iface->next_objid++;
|
next = ctrl_iface->next_objid++;
|
||||||
os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
|
os_snprintf(wpa_s->dbus_new_path, WPAS_DBUS_OBJECT_PATH_MAX,
|
||||||
WPAS_DBUS_NEW_PATH_INTERFACES "/%u",
|
WPAS_DBUS_NEW_PATH_INTERFACES "/%u",
|
||||||
next);
|
next);
|
||||||
if (wpas_dbus_set_path(wpa_s, path)) {
|
|
||||||
wpa_printf(MSG_DEBUG,
|
|
||||||
"Failed to set dbus path for interface %s",
|
|
||||||
wpa_s->ifname);
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
|
obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
|
||||||
if (!obj_desc) {
|
if (!obj_desc) {
|
||||||
@ -1800,19 +1775,21 @@ int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s)
|
|||||||
wpas_dbus_interface_properties,
|
wpas_dbus_interface_properties,
|
||||||
wpas_dbus_interface_signals);
|
wpas_dbus_interface_signals);
|
||||||
|
|
||||||
wpa_printf(MSG_DEBUG, "dbus: Register interface object '%s'", path);
|
wpa_printf(MSG_DEBUG, "dbus: Register interface object '%s'",
|
||||||
if (wpa_dbus_register_object_per_iface(ctrl_iface, path, wpa_s->ifname,
|
wpa_s->dbus_new_path);
|
||||||
obj_desc))
|
if (wpa_dbus_register_object_per_iface(ctrl_iface,
|
||||||
|
wpa_s->dbus_new_path,
|
||||||
|
wpa_s->ifname, obj_desc))
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
wpas_dbus_signal_interface_added(wpa_s);
|
wpas_dbus_signal_interface_added(wpa_s);
|
||||||
|
|
||||||
os_free(path);
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
|
os_free(wpa_s->dbus_new_path);
|
||||||
|
wpa_s->dbus_new_path = NULL;
|
||||||
os_free(obj_desc);
|
os_free(obj_desc);
|
||||||
os_free(path);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -696,7 +696,6 @@ int wpas_dbus_register_iface(struct wpa_supplicant *wpa_s)
|
|||||||
DBusObjectPathVTable vtable = {
|
DBusObjectPathVTable vtable = {
|
||||||
NULL, &wpas_iface_message_handler, NULL, NULL, NULL, NULL
|
NULL, &wpas_iface_message_handler, NULL, NULL, NULL, NULL
|
||||||
};
|
};
|
||||||
char *path;
|
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
/* Do nothing if the control interface is not turned on */
|
/* Do nothing if the control interface is not turned on */
|
||||||
@ -707,21 +706,16 @@ int wpas_dbus_register_iface(struct wpa_supplicant *wpa_s)
|
|||||||
next = ctrl_iface->next_objid++;
|
next = ctrl_iface->next_objid++;
|
||||||
|
|
||||||
/* Create and set the interface's object path */
|
/* Create and set the interface's object path */
|
||||||
path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
|
wpa_s->dbus_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
|
||||||
if (path == NULL)
|
if (wpa_s->dbus_path == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
|
os_snprintf(wpa_s->dbus_path, WPAS_DBUS_OBJECT_PATH_MAX,
|
||||||
WPAS_DBUS_PATH_INTERFACES "/%u",
|
WPAS_DBUS_PATH_INTERFACES "/%u",
|
||||||
next);
|
next);
|
||||||
if (wpa_supplicant_set_dbus_path(wpa_s, path)) {
|
|
||||||
wpa_printf(MSG_DEBUG,
|
|
||||||
"Failed to set dbus path for interface %s",
|
|
||||||
wpa_s->ifname);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Register the message handler for the interface functions */
|
/* Register the message handler for the interface functions */
|
||||||
if (!dbus_connection_register_fallback(con, path, &vtable, wpa_s)) {
|
if (!dbus_connection_register_fallback(con, wpa_s->dbus_path, &vtable,
|
||||||
|
wpa_s)) {
|
||||||
perror("wpas_dbus_register_iface [dbus]");
|
perror("wpas_dbus_register_iface [dbus]");
|
||||||
wpa_printf(MSG_ERROR, "Could not set up DBus message "
|
wpa_printf(MSG_ERROR, "Could not set up DBus message "
|
||||||
"handler for interface %s.", wpa_s->ifname);
|
"handler for interface %s.", wpa_s->ifname);
|
||||||
@ -730,7 +724,6 @@ int wpas_dbus_register_iface(struct wpa_supplicant *wpa_s)
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
os_free(path);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -787,25 +780,6 @@ struct wpa_supplicant * wpa_supplicant_get_iface_by_dbus_path(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* wpa_supplicant_set_dbus_path - Assign a dbus path to an interface
|
|
||||||
* @wpa_s: wpa_supplicant interface structure
|
|
||||||
* @path: dbus path to set on the interface
|
|
||||||
* Returns: 0 on succes, -1 on error
|
|
||||||
*/
|
|
||||||
int wpa_supplicant_set_dbus_path(struct wpa_supplicant *wpa_s,
|
|
||||||
const char *path)
|
|
||||||
{
|
|
||||||
u32 len = strlen (path);
|
|
||||||
if (len >= WPAS_DBUS_OBJECT_PATH_MAX)
|
|
||||||
return -1;
|
|
||||||
if (wpa_s->dbus_path)
|
|
||||||
return -1;
|
|
||||||
wpa_s->dbus_path = os_strdup(path);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wpa_supplicant_get_dbus_path - Get an interface's dbus path
|
* wpa_supplicant_get_dbus_path - Get an interface's dbus path
|
||||||
* @wpa_s: %wpa_supplicant interface structure
|
* @wpa_s: %wpa_supplicant interface structure
|
||||||
|
@ -91,8 +91,6 @@ int wpas_dbus_unregister_iface(struct wpa_supplicant *wpa_s);
|
|||||||
|
|
||||||
|
|
||||||
/* Methods internal to the dbus control interface */
|
/* Methods internal to the dbus control interface */
|
||||||
int wpa_supplicant_set_dbus_path(struct wpa_supplicant *wpa_s,
|
|
||||||
const char *path);
|
|
||||||
const char *wpa_supplicant_get_dbus_path(struct wpa_supplicant *wpa_s);
|
const char *wpa_supplicant_get_dbus_path(struct wpa_supplicant *wpa_s);
|
||||||
struct wpa_supplicant * wpa_supplicant_get_iface_by_dbus_path(
|
struct wpa_supplicant * wpa_supplicant_get_iface_by_dbus_path(
|
||||||
struct wpa_global *global, const char *path);
|
struct wpa_global *global, const char *path);
|
||||||
|
Loading…
Reference in New Issue
Block a user