Bug 113107 - Devlabel can't handle regex-like UUID
Summary: Devlabel can't handle regex-like UUID
Alias: None
Product: Fedora
Classification: Fedora
Component: devlabel   
(Show other bugs)
Version: 1
Hardware: All Linux
Target Milestone: ---
Assignee: Bill Nottingham
QA Contact:
Depends On:
TreeView+ depends on / blocked
Reported: 2004-01-08 15:48 UTC by Gianni Giardina
Modified: 2014-03-17 02:41 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2004-09-08 19:49:32 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
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 15:54 UTC, Gianni Giardina
no flags Details | Diff

Description Gianni Giardina 2004-01-08 15:48:30 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1)

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):

How reproducible:

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
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

The device you are trying to add to devlabel does not show up in

> 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 15:54:40 UTC
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 21:44:19 UTC
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 21:51:39 UTC
nevermind removing '.', these would not be part of the regexp to 
change to _

Comment 4 Gianni Giardina 2004-01-15 11:56:09 UTC
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 12:03:16 UTC
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 15:31:20 UTC
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 

Comment 7 Gary Lerhaupt 2004-01-22 19:18:57 UTC
Fixed and available.


Comment 8 Bill Nottingham 2004-09-08 19:49:32 UTC
Included in current builds.

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