[systemd-devel] usb_id gets bogus serial and makes a mess

Robert Milasan rmilasan at suse.com
Thu Feb 7 11:49:08 PST 2013


On Thu, 07 Feb 2013 16:32:55 -0300
"Cristian Rodríguez" <crrodriguez at opensuse.org> wrote:

> El 07/02/13 11:52, Robert Milasan escribió:
> > Hi, seems that using some strange usb devices with really bogus
> > serial numbers usb_id creates links with junk strings in it:
> 
> >
> > Could be added to usb_id and then use it to validated serial_str and
> > serial.
> >
> 
> Something like this is IMHO better
> 
> static bool is_valid_usb_id(const char *serial)
> {
> 	regex_t preg;
> 	int rc;
> 
> if(!serial) return false;
> 	
> rc = regcomp(&preg, "^[a-zA-Z0-9_-]+$", RULE_REGEX_FLAGS);
> 
> if(rc != 0) return false;
> 
> if (regexec(&preg, serial, 0, NULL, 0) != 0) {
> 	regfree(&preg);
> 	return false;
> }
> regfree(&preg);
> return true;
> }
> 
> But.. should the kernel just reject bogus usb ids ??
> 

The serial is not the usb id, it's just what the kernel gets from the
device and usb_id uses it to created the links in /dev/disk/...

I don't agree with your code (not because is not good), but just
because I followed the coding from udev itself and similar ideas are
already implemented or used in udev.

But anyway, the code shouldn't be an issue, no matter which every is
used, just to be implemented.

-- 
Robert Milasan

L3 Support Engineer
SUSE Linux (http://www.suse.com)
email: rmilasan at suse.com
GPG fingerprint: B6FE F4A8 0FA3 3040 3402  6FE7 2F64 167C 1909 6D1A


More information about the systemd-devel mailing list