chiark / gitweb /
Remove some dead code
[elogind.git] / src / udev / udev-builtin-usb_id.c
index 13d1226393b60269d79272a0130c4dfd5ac47029..dcb2468bf6c67f34522e9037f7fd3c67d908bc07 100644 (file)
@@ -111,7 +111,7 @@ static int set_usb_mass_storage_ifsubtype(char *to, const char *from, size_t len
                         break;
                 }
         }
-        util_strscpy(to, len, type);
+        strscpy(to, len, type);
         return type_num;
 }
 
@@ -143,7 +143,7 @@ static void set_scsi_type(char *to, const char *from, size_t len)
                         break;
                 }
         }
-        util_strscpy(to, len, type);
+        strscpy(to, len, type);
 }
 
 #define USB_DT_DEVICE                        0x01
@@ -189,7 +189,7 @@ static int dev_if_packed_info(struct udev_device *dev, char *ifs_str, size_t len
         pos = 0;
         strpos = 0;
         ifs_str[0] = '\0';
-        while (pos < sizeof(buf) && strpos+7 < len-2) {
+        while (pos < size && strpos+7 < len-2) {
                 struct usb_interface_descriptor *desc;
                 char if_str[8];
 
@@ -273,7 +273,7 @@ static int builtin_usb_id(struct udev_device *dev, int argc, char *argv[], bool
         instance_str[0] = '\0';
 
         /* shortcut, if we are called directly for a "usb_device" type */
-        if (udev_device_get_devtype(dev) != NULL && strcmp(udev_device_get_devtype(dev), "usb_device") == 0) {
+        if (udev_device_get_devtype(dev) != NULL && streq(udev_device_get_devtype(dev), "usb_device")) {
                 dev_if_packed_info(dev, packed_if_str, sizeof(packed_if_str));
                 dev_usb = dev;
                 goto fallback;
@@ -431,6 +431,17 @@ fallback:
                 const char *usb_serial;
 
                 usb_serial = udev_device_get_sysattr_value(dev_usb, "serial");
+                if (usb_serial) {
+                        const unsigned char *p;
+
+                        /* http://msdn.microsoft.com/en-us/library/windows/hardware/gg487321.aspx */
+                        for (p = (unsigned char *)usb_serial; *p != '\0'; p++)
+                                if (*p < 0x20 || *p > 0x7f || *p == ',') {
+                                        usb_serial = NULL;
+                                        break;
+                                }
+                }
+
                 if (usb_serial) {
                         util_replace_whitespace(usb_serial, serial_str, sizeof(serial_str)-1);
                         util_replace_chars(serial_str, NULL);
@@ -438,12 +449,12 @@ fallback:
         }
 
         s = serial;
-        l = util_strpcpyl(&s, sizeof(serial), vendor_str, "_", model_str, NULL);
+        l = strpcpyl(&s, sizeof(serial), vendor_str, "_", model_str, NULL);
         if (serial_str[0] != '\0')
-                l = util_strpcpyl(&s, l, "_", serial_str, NULL);
+                l = strpcpyl(&s, l, "_", serial_str, NULL);
 
         if (instance_str[0] != '\0')
-                util_strpcpyl(&s, l, "-", instance_str, NULL);
+                strpcpyl(&s, l, "-", instance_str, NULL);
 
         udev_builtin_add_property(dev, test, "ID_VENDOR", vendor_str);
         udev_builtin_add_property(dev, test, "ID_VENDOR_ENC", vendor_str_enc);