2013-02-12 10:21:01 +01:00
|
|
|
From 2ffcfb9b45262271019d1751cafc895c3dae8f0e Mon Sep 17 00:00:00 2001
|
|
|
|
From: Robert Milasan <rmilasan@suse.com>
|
|
|
|
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(+)
|
|
|
|
|
2013-02-13 13:01:15 +01:00
|
|
|
Index: systemd-195/src/udev/udev-builtin-usb_id.c
|
|
|
|
===================================================================
|
|
|
|
--- systemd-195.orig/src/udev/udev-builtin-usb_id.c
|
|
|
|
+++ systemd-195/src/udev/udev-builtin-usb_id.c
|
2013-02-12 10:21:01 +01:00
|
|
|
@@ -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"
|
|
|
|
|
2013-02-13 13:01:15 +01:00
|
|
|
+static bool valid_string(const char *str)
|
2013-02-12 10:21:01 +01:00
|
|
|
+{
|
|
|
|
+ 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";
|
2013-02-13 13:01:15 +01:00
|
|
|
@@ -428,10 +449,10 @@ fallback:
|
|
|
|
}
|
|
|
|
|
|
|
|
if (serial_str[0] == '\0') {
|
|
|
|
- const char *usb_serial;
|
|
|
|
+ const char *usb_serial = NULL;
|
2013-02-12 10:21:01 +01:00
|
|
|
|
|
|
|
usb_serial = udev_device_get_sysattr_value(dev_usb, "serial");
|
2013-02-13 13:01:15 +01:00
|
|
|
- if (usb_serial) {
|
|
|
|
+ if (valid_string(usb_serial)) {
|
2013-02-12 10:21:01 +01:00
|
|
|
util_replace_whitespace(usb_serial, serial_str, sizeof(serial_str)-1);
|
|
|
|
util_replace_chars(serial_str, NULL);
|
2013-02-13 13:01:15 +01:00
|
|
|
}
|