forked from drath/libratbag
ratbagd: use strdup_safe for all string copies
Because if we can't strdup a device name or dbus path, we have problems we can't recover from anyway. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
committed by
Benjamin Tissoires
parent
5fff0ece5b
commit
a6d03fde18
@@ -437,7 +437,8 @@ src_ratbagd = [
|
||||
'ratbagd/ratbagd-button.c',
|
||||
'ratbagd/ratbagd-device.c',
|
||||
'ratbagd/ratbagd-profile.c',
|
||||
'ratbagd/ratbagd-resolution.c'
|
||||
'ratbagd/ratbagd-resolution.c',
|
||||
'src/libratbag-util.h'
|
||||
]
|
||||
|
||||
deps_ratbagd = [
|
||||
|
||||
@@ -38,6 +38,8 @@
|
||||
#include "shared-macro.h"
|
||||
#include "shared-rbtree.h"
|
||||
|
||||
#include "libratbag-util.h"
|
||||
|
||||
struct ratbagd_device {
|
||||
struct ratbagd *ctx;
|
||||
RBNode node;
|
||||
@@ -104,20 +106,12 @@ static int ratbagd_device_list_profiles(sd_bus *bus,
|
||||
if (!profile)
|
||||
continue;
|
||||
|
||||
profiles[i] = strdup(ratbagd_profile_get_path(profile));
|
||||
if (!profiles[i])
|
||||
goto error;
|
||||
profiles[i] = strdup_safe(ratbagd_profile_get_path(profile));
|
||||
}
|
||||
|
||||
profiles[i] = NULL;
|
||||
*paths = profiles;
|
||||
return 1;
|
||||
|
||||
error:
|
||||
for (i = 0; profiles[i]; ++i)
|
||||
free(profiles[i]);
|
||||
free(profiles);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
static int ratbagd_device_get_device_name(sd_bus *bus,
|
||||
@@ -387,9 +381,7 @@ int ratbagd_device_new(struct ratbagd_device **out,
|
||||
rbnode_init(&device->node);
|
||||
device->lib_device = ratbag_device_ref(lib_device);
|
||||
|
||||
device->name = strdup(name);
|
||||
if (!device->name)
|
||||
return -ENOMEM;
|
||||
device->name = strdup_safe(name);
|
||||
|
||||
r = sd_bus_path_encode(RATBAGD_OBJ_ROOT "/device",
|
||||
device->name,
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <systemd/sd-bus.h>
|
||||
#include <systemd/sd-event.h>
|
||||
#include "ratbagd.h"
|
||||
#include "libratbag-util.h"
|
||||
#include "shared-macro.h"
|
||||
|
||||
struct ratbagd_profile {
|
||||
@@ -530,20 +531,12 @@ static int ratbagd_profile_list_resolutions(sd_bus *bus,
|
||||
if (!resolution)
|
||||
continue;
|
||||
|
||||
resolutions[i] = strdup(ratbagd_resolution_get_path(resolution));
|
||||
if (!resolutions[i])
|
||||
goto error;
|
||||
resolutions[i] = strdup_safe(ratbagd_resolution_get_path(resolution));
|
||||
}
|
||||
|
||||
resolutions[i] = NULL;
|
||||
*paths = resolutions;
|
||||
return 1;
|
||||
|
||||
error:
|
||||
for (i = 0; resolutions[i]; ++i)
|
||||
free(resolutions[i]);
|
||||
free(resolutions);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
|
||||
@@ -607,20 +600,12 @@ static int ratbagd_profile_list_buttons(sd_bus *bus,
|
||||
if (!button)
|
||||
continue;
|
||||
|
||||
buttons[i] = strdup(ratbagd_button_get_path(button));
|
||||
if (!buttons[i])
|
||||
goto error;
|
||||
buttons[i] = strdup_safe(ratbagd_button_get_path(button));
|
||||
}
|
||||
|
||||
buttons[i] = NULL;
|
||||
*paths = buttons;
|
||||
return 1;
|
||||
|
||||
error:
|
||||
for (i = 0; buttons[i]; ++i)
|
||||
free(buttons[i]);
|
||||
free(buttons);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
int ratbagd_profile_register_buttons(struct sd_bus *bus,
|
||||
@@ -683,20 +668,12 @@ static int ratbagd_profile_list_leds(sd_bus *bus,
|
||||
if (!led)
|
||||
continue;
|
||||
|
||||
leds[i] = strdup(ratbagd_led_get_path(led));
|
||||
if (!leds[i])
|
||||
goto error;
|
||||
leds[i] = strdup_safe(ratbagd_led_get_path(led));
|
||||
}
|
||||
|
||||
leds[i] = NULL;
|
||||
*paths = leds;
|
||||
return 1;
|
||||
|
||||
error:
|
||||
for (i = 0; leds[i]; ++i)
|
||||
free(leds[i]);
|
||||
free(leds);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
int ratbagd_profile_register_leds(struct sd_bus *bus,
|
||||
|
||||
Reference in New Issue
Block a user