diff --git a/src/libsystemd/sd-device/device-private.c b/src/libsystemd/sd-device/device-private.c index 1ad7713ec7e..aa1ac3905a4 100644 --- a/src/libsystemd/sd-device/device-private.c +++ b/src/libsystemd/sd-device/device-private.c @@ -316,34 +316,33 @@ static int device_amend(sd_device *device, const char *key, const char *value) { if (r < 0) return log_device_debug_errno(device, r, "sd-device: Failed to set SEQNUM to '%s': %m", value); } else if (streq(key, "DEVLINKS")) { - const char *word, *state; - size_t l; + for (const char *p = value;;) { + _cleanup_free_ char *word = NULL; - FOREACH_WORD(word, l, value, state) { - char devlink[l + 1]; - - strncpy(devlink, word, l); - devlink[l] = '\0'; - - r = device_add_devlink(device, devlink); + r = extract_first_word(&p, &word, NULL, 0); if (r < 0) - return log_device_debug_errno(device, r, "sd-device: Failed to add devlink '%s': %m", devlink); + return r; + if (r == 0) + break; + + r = device_add_devlink(device, word); + if (r < 0) + return log_device_debug_errno(device, r, "sd-device: Failed to add devlink '%s': %m", word); } } else if (STR_IN_SET(key, "TAGS", "CURRENT_TAGS")) { - const char *word, *state; - size_t l; + for (const char *p = value;;) { + _cleanup_free_ char *word = NULL; - FOREACH_WORD_SEPARATOR(word, l, value, ":", state) { - char tag[l + 1]; - - (void) strncpy(tag, word, l); - tag[l] = '\0'; - - r = device_add_tag(device, tag, streq(key, "CURRENT_TAGS")); + r = extract_first_word(&p, &word, ":", EXTRACT_DONT_COALESCE_SEPARATORS); if (r < 0) - return log_device_debug_errno(device, r, "sd-device: Failed to add tag '%s': %m", tag); - } + return r; + if (r == 0) + break; + r = device_add_tag(device, word, streq(key, "CURRENT_TAGS")); + if (r < 0) + return log_device_debug_errno(device, r, "sd-device: Failed to add tag '%s': %m", word); + } } else { r = device_add_property_internal(device, key, value); if (r < 0)