diff options
Diffstat (limited to 'src/libsystemd')
-rw-r--r-- | src/libsystemd/sd-device/device-private.c | 2 | ||||
-rw-r--r-- | src/libsystemd/sd-device/device-private.h | 2 | ||||
-rw-r--r-- | src/libsystemd/sd-device/sd-device.c | 40 |
3 files changed, 35 insertions, 9 deletions
diff --git a/src/libsystemd/sd-device/device-private.c b/src/libsystemd/sd-device/device-private.c index e9d54f514e..9ded8c17a1 100644 --- a/src/libsystemd/sd-device/device-private.c +++ b/src/libsystemd/sd-device/device-private.c @@ -351,6 +351,8 @@ static int device_amend(sd_device *device, const char *key, const char *value) { return r; if (r == 0) break; + if (isempty(word)) + continue; r = device_add_tag(device, word, streq(key, "CURRENT_TAGS")); if (r < 0) diff --git a/src/libsystemd/sd-device/device-private.h b/src/libsystemd/sd-device/device-private.h index 740c58438c..b903d1afd6 100644 --- a/src/libsystemd/sd-device/device-private.h +++ b/src/libsystemd/sd-device/device-private.h @@ -38,7 +38,7 @@ void device_set_db_persist(sd_device *device); void device_set_devlink_priority(sd_device *device, int priority); int device_ensure_usec_initialized(sd_device *device, sd_device *device_old); int device_add_devlink(sd_device *device, const char *devlink); -void device_remove_devlink(sd_device *device, const char *devlink); +int device_remove_devlink(sd_device *device, const char *devlink); bool device_has_devlink(sd_device *device, const char *devlink); int device_add_property(sd_device *device, const char *property, const char *value); int device_add_propertyf(sd_device *device, const char *key, const char *format, ...) _printf_(3, 4); diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index e86ec3e75b..58067414cd 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -1439,7 +1439,7 @@ _public_ int sd_device_get_diskseq(sd_device *device, uint64_t *ret) { static bool is_valid_tag(const char *tag) { assert(tag); - return !strchr(tag, ':') && !strchr(tag, ' '); + return in_charset(tag, ALPHANUMERICAL "-_") && filename_is_valid(tag); } int device_add_tag(sd_device *device, const char *tag, bool both) { @@ -1473,34 +1473,58 @@ int device_add_tag(sd_device *device, const char *tag, bool both) { return 0; } +static char *prefix_dev(const char *p) { + assert(p); + + if (path_startswith(p, "/dev/")) + return strdup(p); + + return path_join("/dev/", p); +} + int device_add_devlink(sd_device *device, const char *devlink) { + char *p; int r; assert(device); assert(devlink); - r = set_put_strdup(&device->devlinks, devlink); + if (!path_is_safe(devlink)) + return -EINVAL; + + p = prefix_dev(devlink); + if (!p) + return -ENOMEM; + + path_simplify(p); + + r = set_ensure_consume(&device->devlinks, &path_hash_ops_free, p); if (r < 0) return r; device->devlinks_generation++; device->property_devlinks_outdated = true; - return 0; + return r; /* return 1 when newly added, 0 when already exists */ } -void device_remove_devlink(sd_device *device, const char *devlink) { - _cleanup_free_ char *s = NULL; +int device_remove_devlink(sd_device *device, const char *devlink) { + _cleanup_free_ char *p = NULL, *s = NULL; assert(device); assert(devlink); - s = set_remove(device->devlinks, devlink); + p = prefix_dev(devlink); + if (!p) + return -ENOMEM; + + s = set_remove(device->devlinks, p); if (!s) - return; + return 0; /* does not exist */ device->devlinks_generation++; device->property_devlinks_outdated = true; + return 1; /* removed */ } bool device_has_devlink(sd_device *device, const char *devlink) { @@ -2270,7 +2294,7 @@ int device_cache_sysattr_value(sd_device *device, const char *key, char *value) return -ENOMEM; } - r = hashmap_ensure_put(&device->sysattr_values, &string_hash_ops_free_free, new_key, value); + r = hashmap_ensure_put(&device->sysattr_values, &path_hash_ops_free_free, new_key, value); if (r < 0) return r; |