udev-builtin-net_id: do not assume "type" attribute exists
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 25 Sep 2018 09:29:54 +0000 (11:29 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 25 Sep 2018 09:29:54 +0000 (11:29 +0200)
It *should*, but who knows, let's be more defensive here.

CID #1395805.

src/udev/udev-builtin-net_id.c

index d61826c..5341d37 100644 (file)
@@ -317,15 +317,14 @@ static int dev_pci_slot(struct udev_device *dev, struct netnames *names) {
                  * provide the port number in the 'dev_id' sysfs attribute instead of 'dev_port',
                  * which thus stays initialized as 0. */
                 if (dev_port == 0) {
-                        unsigned long type;
-
                         attr = udev_device_get_sysattr_value(dev, "type");
-                        /* The 'type' attribute always exists. */
-                        type = strtoul(attr, NULL, 10);
-                        if (type == ARPHRD_INFINIBAND) {
-                                attr = udev_device_get_sysattr_value(dev, "dev_id");
-                                if (attr)
-                                        dev_port = strtoul(attr, NULL, 16);
+                        if (attr) {
+                                unsigned long type = strtoul(attr, NULL, 10);
+                                if (type == ARPHRD_INFINIBAND) {
+                                        attr = udev_device_get_sysattr_value(dev, "dev_id");
+                                        if (attr)
+                                                dev_port = strtoul(attr, NULL, 16);
+                                }
                         }
                 }
         }