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 --- macvlan.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'macvlan.c') diff --git a/macvlan.c b/macvlan.c index 021d394..092f1dd 100644 --- a/macvlan.c +++ b/macvlan.c @@ -239,7 +239,12 @@ macvlan_create(const char *name, struct device_type *devtype, return NULL; dev = &mvdev->dev; - device_init(dev, devtype, name); + if (device_init(dev, devtype, name) < 0) { + device_cleanup(dev); + free(mvdev); + return NULL; + } + dev->config_pending = true; mvdev->set_state = dev->set_state; -- cgit v1.2.1