From 522456b9f3ab07a78de17bf693abead4a296b028 Mon Sep 17 00:00:00 2001 From: Hans Dedecker Date: Sun, 12 Aug 2018 22:08:22 +0200 Subject: device: gracefully handle device names exceeding IFNAMESIZ Instead of truncating the device name when it exceeds IFNAMSIZ length; let device_set_ifname return an error code and do not add the device to the device list. This avoids possible issues with device names becoming identical due the truncation and as a result unexpected behavior. Further let the different device types gracefully handle the error code returned by device_init Signed-off-by: Hans Dedecker --- alias.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'alias.c') diff --git a/alias.c b/alias.c index 3b14b87..951e046 100644 --- a/alias.c +++ b/alias.c @@ -124,7 +124,11 @@ alias_device_create(const char *name, struct device_type *devtype, strcpy(alias->name, name); alias->dev.set_state = alias_device_set_state; alias->dev.hidden = true; - device_init_virtual(&alias->dev, devtype, NULL); + if (device_init_virtual(&alias->dev, devtype, NULL) < 0) { + free(alias); + return NULL; + } + alias->avl.key = alias->name; avl_insert(&aliases, &alias->avl); alias->dep.alias = true; -- cgit v1.2.1