Bug 113107 - Devlabel can't handle regex-like UUID
Devlabel can't handle regex-like UUID
Status: CLOSED RAWHIDE
Product: Fedora
Classification: Fedora
Component: devlabel (Show other bugs)
1
All Linux
medium Severity medium
: ---
: ---
Assigned To: Bill Nottingham
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2004-01-08 10:48 EST by Gianni Giardina
Modified: 2014-03-16 22:41 EDT (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2004-09-08 15:49:32 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
The patched source rpm which fix the bug. (36.79 KB, patch)
2004-01-08 10:54 EST, Gianni Giardina
no flags Details | Diff

  None (edit)
Description Gianni Giardina 2004-01-08 10:48:30 EST
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1)
Gecko/20030225

Description of problem:
Devlabel can't handle regex-like stings as UUID, such as strings that
contain the carachter '*'.

For example, using my 256 MB Iomega USB Minidrive I obtain the
following UUID: S80:75I0MEGAMini256*IOM
When I try the add command with this device (both by the -d or the -u
switch), devlabel complain something wrong with the UUID.

The problem is that inside devlabel's code all UUID processings are
made by grep. Say, for example, the variable Uuid has value I've
written above, then the code:

  echo "${device_mappings[*]}" | grep "$Uuid"

won't do the right job in finding all device mappings containin such UUID.

I've solved the problem by replacing such GREPs with AWKs. I wrote a
patch which I've included in an RPM I currently use on the machines
inside the network I administer. This patch also allows devlabel to
handle UUIDs containing the character '='. The patch, finally, solves
another minor bug (see error logs below).

I send in attachment the patched source rpm.

Version-Release number of selected component (if applicable):
devlabel-0.42.05-2

How reproducible:
Always

Steps to Reproduce:
1. You need a device whose UUID contains some regex meta-character.
For example, the 256 MB Iomega USB Minidrive.
2. Plug the device. Suppose it becomes /dev/sda on your system
(therefore its partition is /dev/sda1).
3. Issue the command:
# devlabel printid -d /dev/sda1
S80:75I0MEGAMini256*IOMsector4
4. Try:
# devlabel add -d /dev/sda1 -s /dev/minidrive
5. Try also:
# devlabel add -u S80:75I0MEGAMini256*IOMsector4 -s /dev/minidrive

Actual Results:  Step 4 and 5: devlabel complains it cannot add the
device to /etc/sysconfig/devlabel nor create the symlink.

(logs coming below)

Expected Results:  Step 4 and 5: devlabel should have added the device
to /etc/sysconfig/devlabel and created the symlink.

Additional info:

** Error messages issued by devlabel **

> Step 4

Failure.
The device you are trying to add to devlabel does not show up in
/proc/partitions.

> Step 5

Could not add a symlink to the device with this UUID.
Either no device could be found or multiple devices have this ID.
 
If multiple devices have this ID because it is part of a multipath set,
then you can add with the --multipath option to ensure device naming
/sbin/devlabel: line 425: 22: Bad file descriptor

NOTE: the last error line above ("Bad file descriptor") is a message
issued by bash and refers to what I've called "a minor bug" in the
Description section above.
Comment 1 Gianni Giardina 2004-01-08 10:54:40 EST
Created attachment 96829 [details]
The patched source rpm which fix the bug.

The patch contained in the rpm is SOURCES/devlabel-0.42.05-regex_uuid.patch
Comment 2 Gary Lerhaupt 2004-01-12 16:44:19 EST
How about this instead?

At the end of get_id

ID=`echo $ID | sed 's/[\[\\\/\=\^\*\$\.]/_/'`

This replaces any character of the set {[,\,/,=,^,*,$,.} with a '_'.

I think this works better.
Comment 3 Gary Lerhaupt 2004-01-12 16:51:39 EST
nevermind removing '.', these would not be part of the regexp to 
change to _
Comment 4 Gianni Giardina 2004-01-15 06:56:09 EST
Gary, I'm not sure it works better. Surely it's much simpler and it
works... but not always.

There are two ways to solve the problem:

1) making Devlabel handle regex-UUID;
2) avoiding generation of regex-UUID to be passed to Devlabel.

I choose the first one, because I think it's the most reliable, you
the second one, because - I believe - it's the simplest one.

But you should be aware that your solution theoretically reduces the 
use range of Devlabel. I mean, it increases the likelyhood to find the
same UUID for two (very similar) devices.

Say a company sells two models of the same kind of device and that
get_id now returns ABCDEFG=X for the first one and ABCDEFG*X for the
second one. If both values are assigned to the ID variable the command 

echo $ID | sed 's/[\[\\\/\=\^\*\$\.]/_/'

prints always ABCDEFG_X

Yes, I know, it's very unlikely but what if you tomorrow decide, for
some reason, to use egrep instead of grep in Devlabel's code? You
should add more characters in the replace set used by sed and the
descrideb situation would become more likely.

Anyway, it's all just conjecture...
Comment 5 Gianni Giardina 2004-01-15 07:03:16 EST
If you decide to use the code

ID=`echo $ID | sed 's/[\[\\\/\=\^\*\$\.]/_/'`

I think you don't need to quote the characters. To express the set
{[,\,/,=,^,*,$,.} it's enough

ID=`echo $ID | sed 's/[[\/=^*$.]/_/'`
Comment 6 Gary Lerhaupt 2004-01-15 10:31:20 EST
You are correct, I did choose that fix because it is the simpler of 
the two.  We debated over here that it would reduce the range, but as 
you said, the likelihood of collisions based on these characters is 
low.
Comment 7 Gary Lerhaupt 2004-01-22 14:18:57 EST
Fixed and available.

http://linux.dell.com/blog/2004/01/22/#1319
Comment 8 Bill Nottingham 2004-09-08 15:49:32 EDT
Included in current builds.

Note You need to log in before you can comment on or make changes to this bug.