mirror of
https://github.com/systemd/systemd.git
synced 2025-01-26 14:04:03 +03:00
sd-device: reset sysname and sysnum on renaming
This commit is contained in:
parent
f5a75f2027
commit
60e50fb20d
@ -773,6 +773,10 @@ int device_rename(sd_device *device, const char *name) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
/* Here, only clear the sysname and sysnum. They will be set when requested. */
|
||||
device->sysnum = NULL;
|
||||
device->sysname = mfree(device->sysname);
|
||||
|
||||
r = sd_device_get_property_value(device, "INTERFACE", &interface);
|
||||
if (r == -ENOENT)
|
||||
return 0;
|
||||
|
@ -869,15 +869,21 @@ int udev_event_spawn(
|
||||
}
|
||||
|
||||
static int rename_netif(UdevEvent *event) {
|
||||
sd_device *dev = event->dev;
|
||||
const char *oldname;
|
||||
sd_device *dev;
|
||||
unsigned flags;
|
||||
int ifindex, r;
|
||||
|
||||
assert(event);
|
||||
|
||||
if (!event->name)
|
||||
return 0; /* No new name is requested. */
|
||||
|
||||
r = sd_device_get_sysname(dev, &oldname);
|
||||
dev = ASSERT_PTR(event->dev);
|
||||
|
||||
/* Read sysname from cloned sd-device object, otherwise use-after-free is triggered, as the
|
||||
* main object will be renamed and dev->sysname will be freed in device_rename(). */
|
||||
r = sd_device_get_sysname(event->dev_db_clone, &oldname);
|
||||
if (r < 0)
|
||||
return log_device_error_errno(dev, r, "Failed to get sysname: %m");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user