On Thu, 7 Feb 2013 15:52:20 +0100
"Robert Milasan" <[email protected]> wrote:
> Hi, seems that using some strange usb devices with really bogus serial
> numbers usb_id creates links with junk strings in it:
>
> /dev/disk/by-id/usb-TSSTcorp_BDDVDW_SE-506AB_㡒䍌䜶䉗ぁㄴ㌴†ँ-0:0
>
> Initially was believed that usb_id is to blame, then the kernel, but
> it turns out that really the usb cd/dvd drive has this bogus serial
> number:
>
> output from dmesg:
> [ 538.200160] usb 1-2: new high-speed USB device number 5 using
> ehci_hcd [ 538.335067] usb 1-2: New USB device found, idVendor=0e8d,
> idProduct=1956 [ 538.335080] usb 1-2: New USB device strings: Mfr=1,
> Product=2, SerialNumber=3 [ 538.335089] usb 1-2: Product: MT1956
> [ 538.335097] usb 1-2: Manufacturer: MediaTek Inc
> [ 538.335105] usb 1-2: SerialNumber:
> \xffffffe3\xffffffa1\xffffff92\xffffffe4\xffffff8d\xffffff8c\xffffffe4\xffffff9c\xffffffb6\xffffffe4\xffffff89\xffffff97\xffffffe3\xffffff81\xffffff81\xffffffe3\xffffff84\xffffffb4\xffffffe3\xffffff8c\xffffffb4\xffffffe2\xffffff80\xffffffa0\xffffffe0\xffffffa4\xffffff81
> [ 538.337540] scsi6 : usb-storage 1-2:1.0 [ 539.341385] scsi
> 6:0:0:0: CD-ROM TSSTcorp BDDVDW SE-506AB TS00 PQ: 0 ANSI:
> 0 [ 539.354240] sr0: scsi3-mmc drive: 0x/24x writer dvd-ram cd/rw
> xa/form2 cdda tray [ 539.354777] sr 6:0:0:0: Attached scsi CD-ROM sr0
> [ 539.355122] sr 6:0:0:0: Attached scsi generic sg2 type 5
>
> output of command: udevadm test-builtin usb_id /block/sr0
> udev_device_new_from_syspath: device 0x9c84d58 has devpath
> '/devices/pci0000:00/0000:00:1d.7/usb1/1-2' udev_builtin_add_property:
> ID_VENDOR=TSSTcorp udev_builtin_add_property: ID_VENDOR_ENC=TSSTcorp
> udev_builtin_add_property: ID_VENDOR_ID=0e8d
> udev_builtin_add_property: ID_MODEL=BDDVDW_SE-506AB
> udev_builtin_add_property: ID_MODEL_ENC=BDDVDW\x20SE-506AB\x20
> udev_builtin_add_property: ID_MODEL_ID=1956
> udev_builtin_add_property: ID_REVISION=TS00
> udev_builtin_add_property:
> ID_SERIAL=TSSTcorp_BDDVDW_SE-506AB_㡒䍌䜶䉗ぁㄴ㌴†ँ-0:0
> udev_builtin_add_property: ID_SERIAL_SHORT=㡒䍌䜶䉗ぁㄴ㌴†ँ
> udev_builtin_add_property: ID_TYPE=cd udev_builtin_add_property:
> ID_INSTANCE=0:0 udev_builtin_add_property: ID_BUS=usb
> udev_builtin_add_property: ID_USB_INTERFACES=:080250:
> udev_builtin_add_property: ID_USB_INTERFACE_NUM=00
> udev_builtin_add_property: ID_USB_DRIVER=usb-storage
>
> Wouldn't be a good idea to add a string validator for the serial
> number and if it doesn't fall into the valid options, then just set
> the serial to 000000000000000000000 or something like this?
>
> I'm not sure, but don't think from the usb_id point the serial matters
> too much.
>
> Was thinking that this function:
>
> static bool valid_string(const char *serial)
> {
> const char *s;
>
> if (!serial)
> return false;
> for (s = serial; *s != '\0'; s++) {
> if ((*s >= 'a' && *s <= 'z') ||
> (*s >= 'A' && *s <= 'Z') ||
> (*s >= '0' && *s <= '9') ||
> *s == '-' || *s == '_')
> continue;
> else
> return false;
> }
> return true;
> }
>
> Could be added to usb_id and then use it to validated serial_str and
> serial.
>
Here is a simple patch, just don't use the serial if it's bogus.
--
Robert Milasan
L3 Support Engineer
SUSE Linux (http://www.suse.com)
email: [email protected]
GPG fingerprint: B6FE F4A8 0FA3 3040 3402 6FE7 2F64 167C 1909 6D1A
>From 2ffcfb9b45262271019d1751cafc895c3dae8f0e Mon Sep 17 00:00:00 2001
From: Robert Milasan <[email protected]>
Date: Sun, 10 Feb 2013 11:00:20 +0100
Subject: [PATCH] usb_id: some strange devices have a very bogus or strange serial
numer, making a mess in /dev/disk/by-id. Let's check if the
serial number is a valid, otherwise don't use it.
---
src/udev/udev-builtin-usb_id.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/src/udev/udev-builtin-usb_id.c b/src/udev/udev-builtin-usb_id.c
index 7ce401d..9e407c5 100644
--- a/src/udev/udev-builtin-usb_id.c
+++ b/src/udev/udev-builtin-usb_id.c
@@ -23,6 +23,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
+#include <stdbool.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
@@ -31,6 +32,26 @@
#include "udev.h"
+static bool validate_string(const char *str)
+{
+ const char *s;
+
+ if (!str)
+ return false;
+
+ for (s = str; *s != '\0'; s++) {
+ if ((*s >= 'a' && *s <= 'z') ||
+ (*s >= 'A' && *s <= 'Z') ||
+ (*s >= '0' && *s <= '9') ||
+ *s == '-' || *s == '_')
+ continue;
+ else
+ return false;
+ }
+
+ return true;
+}
+
static void set_usb_iftype(char *to, int if_class_num, size_t len)
{
const char *type = "generic";
@@ -431,6 +452,8 @@ fallback:
const char *usb_serial;
usb_serial = udev_device_get_sysattr_value(dev_usb, "serial");
+ if (!validate_string(usb_serial))
+ usb_serial = NULL;
if (usb_serial) {
util_replace_whitespace(usb_serial, serial_str, sizeof(serial_str)-1);
util_replace_chars(serial_str, NULL);
--
1.7.10.4
_______________________________________________
systemd-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/systemd-devel