* Re: [PATCH] fix NAME="foo-%c{N}" gets a truncated name
2004-03-03 22:43 [PATCH] fix NAME="foo-%c{N}" gets a truncated name Patrick Mansfield
@ 2004-03-03 22:58 ` Kay Sievers
2004-03-03 23:46 ` Kay Sievers
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Kay Sievers @ 2004-03-03 22:58 UTC (permalink / raw)
To: linux-hotplug
On Wed, 2004-03-03 at 23:43, Patrick Mansfield wrote:
> Here is a fix and a new test for the problem Atul hit, where if we have a
> NAME based on a result of the form:
>
> NAME="foo-%c{7}"
>
> udev truncates the name. Without any prefix (the foo- in this example),
> the rule was working OK.
>
> === namedev.c 1.122 vs edited ==> --- 1.122/namedev.c Tue Mar 2 21:00:21 2004
> +++ edited/namedev.c Wed Mar 3 14:16:54 2004
> @@ -285,7 +285,7 @@
> dbg("requested part of result string not found");
> break;
> }
> - strnfieldcat(string, udev->program_result + spos, slen+1);
> + strnfieldcat(string, udev->program_result + spos, maxsize);
> dbg("substitute part of result string '%s'", pos);
No, this doesn't work. The string part of the string is
not \0 terminated, so we need to truncate after the computed length.
BUS="scsi", PROGRAM="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL="sda3", NAME="my-%c{6}"
TEST 24: lots of arguments and characters before %c{N}
device 'block/sda/sda3' expecting node 'my-foo8'
add: error
udev-root/
`-- my-foo8 foo9
thanks,
Kay
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH] fix NAME="foo-%c{N}" gets a truncated name
2004-03-03 22:43 [PATCH] fix NAME="foo-%c{N}" gets a truncated name Patrick Mansfield
2004-03-03 22:58 ` Kay Sievers
@ 2004-03-03 23:46 ` Kay Sievers
2004-03-03 23:57 ` Patrick Mansfield
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Kay Sievers @ 2004-03-03 23:46 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1: Type: text/plain, Size: 381 bytes --]
On Wed, Mar 03, 2004 at 02:43:34PM -0800, Patrick Mansfield wrote:
> Here is a fix and a new test for the problem Atul hit, where if we have a
> NAME based on a result of the form:
>
> NAME="foo-%c{7}"
>
> udev truncates the name. Without any prefix (the foo- in this example),
> the rule was working OK.
Here is a fix for the fix :)
Sorry, I broke it yesterday.
thanks,
Kay
[-- Attachment #2: 02-bugfix-c-char.patch --]
[-- Type: text/plain, Size: 966 bytes --]
===== namedev.c 1.122 vs edited =====
--- 1.122/namedev.c Wed Mar 3 06:00:21 2004
+++ edited/namedev.c Thu Mar 4 00:40:03 2004
@@ -214,6 +214,7 @@
struct sysfs_device *sysfs_device)
{
char temp[NAME_SIZE];
+ char temp2[NAME_SIZE];
char *tail;
char *pos;
char *attr;
@@ -277,6 +278,7 @@
i = atoi(attr);
if (i > 0) {
foreach_strpart(udev->program_result, " \n\r", spos, slen) {
+ strnfieldcpy(temp2, udev->program_result + spos, slen+1);
i--;
if (i == 0)
break;
@@ -285,8 +287,8 @@
dbg("requested part of result string not found");
break;
}
- strnfieldcat(string, udev->program_result + spos, slen+1);
- dbg("substitute part of result string '%s'", pos);
+ strnfieldcat(string, temp2, maxsize);
+ dbg("substitute part of result string '%s'", temp2);
} else {
strnfieldcat(string, udev->program_result, maxsize);
dbg("substitute result string '%s'", udev->program_result);
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH] fix NAME="foo-%c{N}" gets a truncated name
2004-03-03 22:43 [PATCH] fix NAME="foo-%c{N}" gets a truncated name Patrick Mansfield
2004-03-03 22:58 ` Kay Sievers
2004-03-03 23:46 ` Kay Sievers
@ 2004-03-03 23:57 ` Patrick Mansfield
2004-03-04 0:56 ` Greg KH
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Patrick Mansfield @ 2004-03-03 23:57 UTC (permalink / raw)
To: linux-hotplug
On Thu, Mar 04, 2004 at 12:46:33AM +0100, Kay Sievers wrote:
> On Wed, Mar 03, 2004 at 02:43:34PM -0800, Patrick Mansfield wrote:
> > Here is a fix and a new test for the problem Atul hit, where if we have a
> > NAME based on a result of the form:
> >
> > NAME="foo-%c{7}"
> >
> > udev truncates the name. Without any prefix (the foo- in this example),
> > the rule was working OK.
>
> Here is a fix for the fix :)
>
> Sorry, I broke it yesterday.
I have a patch without a temp string, but your patch works and is simpler.
Here is a patch for some new tests.
=== test/udev-test.pl 1.40 vs edited ==--- 1.40/test/udev-test.pl Fri Feb 27 19:36:01 2004
+++ edited/test/udev-test.pl Wed Mar 3 15:21:04 2004
@@ -262,6 +262,24 @@
EOF
},
{
+ desc => "characters before the %c{N} substitution",
+ subsys => "block",
+ devpath => "block/sda/sda3",
+ expected => "my-foo9" ,
+ conf => <<EOF
+BUS="scsi", PROGRAM="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL="sda3", NAME="my-%c{7}"
+EOF
+ },
+ {
+ desc => "substitute the second to last argument",
+ subsys => "block",
+ devpath => "block/sda/sda3",
+ expected => "my-foo8" ,
+ conf => <<EOF
+BUS="scsi", PROGRAM="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL="sda3", NAME="my-%c{6}"
+EOF
+ },
+ {
desc => "program result substitution (numbered part of)",
subsys => "block",
devpath => "block/sda/sda3",
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH] fix NAME="foo-%c{N}" gets a truncated name
2004-03-03 22:43 [PATCH] fix NAME="foo-%c{N}" gets a truncated name Patrick Mansfield
` (2 preceding siblings ...)
2004-03-03 23:57 ` Patrick Mansfield
@ 2004-03-04 0:56 ` Greg KH
2004-03-04 0:56 ` Greg KH
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Greg KH @ 2004-03-04 0:56 UTC (permalink / raw)
To: linux-hotplug
On Thu, Mar 04, 2004 at 12:46:33AM +0100, Kay Sievers wrote:
> On Wed, Mar 03, 2004 at 02:43:34PM -0800, Patrick Mansfield wrote:
> > Here is a fix and a new test for the problem Atul hit, where if we have a
> > NAME based on a result of the form:
> >
> > NAME="foo-%c{7}"
> >
> > udev truncates the name. Without any prefix (the foo- in this example),
> > the rule was working OK.
>
> Here is a fix for the fix :)
>
> Sorry, I broke it yesterday.
Applied, thanks.
greg k-h
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH] fix NAME="foo-%c{N}" gets a truncated name
2004-03-03 22:43 [PATCH] fix NAME="foo-%c{N}" gets a truncated name Patrick Mansfield
` (3 preceding siblings ...)
2004-03-04 0:56 ` Greg KH
@ 2004-03-04 0:56 ` Greg KH
2004-03-04 3:09 ` Kay Sievers
2004-03-04 18:57 ` Greg KH
6 siblings, 0 replies; 8+ messages in thread
From: Greg KH @ 2004-03-04 0:56 UTC (permalink / raw)
To: linux-hotplug
On Wed, Mar 03, 2004 at 03:57:04PM -0800, Patrick Mansfield wrote:
>
> Here is a patch for some new tests.
Applied, thanks.
greg k-h
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH] fix NAME="foo-%c{N}" gets a truncated name
2004-03-03 22:43 [PATCH] fix NAME="foo-%c{N}" gets a truncated name Patrick Mansfield
` (4 preceding siblings ...)
2004-03-04 0:56 ` Greg KH
@ 2004-03-04 3:09 ` Kay Sievers
2004-03-04 18:57 ` Greg KH
6 siblings, 0 replies; 8+ messages in thread
From: Kay Sievers @ 2004-03-04 3:09 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1: Type: text/plain, Size: 353 bytes --]
On Wed, Mar 03, 2004 at 04:56:34PM -0800, Greg KH wrote:
> On Wed, Mar 03, 2004 at 03:57:04PM -0800, Patrick Mansfield wrote:
> >
> > Here is a patch for some new tests.
>
> Applied, thanks.
Here is a small improvement, which looks much better.
Hey Pat, thanks a lot for finding the recent bug, hope this one will
not break it again :)
thanks,
Kay
[-- Attachment #2: 01-better-foreach_strpart.patch --]
[-- Type: text/plain, Size: 3184 bytes --]
===== namedev.c 1.123 vs edited =====
--- 1.123/namedev.c Thu Mar 4 01:40:03 2004
+++ edited/namedev.c Thu Mar 4 03:59:52 2004
@@ -220,8 +220,9 @@
char *attr;
int len;
int i;
- int spos, slen;
char c;
+ char *spos;
+ int slen;
struct sysfs_attribute *tmpattr;
pos = string;
@@ -278,7 +279,6 @@
i = atoi(attr);
if (i > 0) {
foreach_strpart(udev->program_result, " \n\r", spos, slen) {
- strnfieldcpy(temp2, udev->program_result + spos, slen+1);
i--;
if (i == 0)
break;
@@ -287,6 +287,7 @@
dbg("requested part of result string not found");
break;
}
+ strnfieldcpy(temp2, spos, slen+1);
strnfieldcat(string, temp2, maxsize);
dbg("substitute part of result string '%s'", temp2);
} else {
===== udev-add.c 1.59 vs edited =====
--- 1.59/udev-add.c Thu Mar 4 01:51:28 2004
+++ edited/udev-add.c Thu Mar 4 03:32:07 2004
@@ -195,7 +195,8 @@
gid_t gid = 0;
int i;
int tail;
- int pos, len;
+ char *pos;
+ int len;
strfieldcpy(filename, udev_root);
strfieldcat(filename, dev->name);
@@ -281,7 +282,7 @@
/* create symlink if requested */
foreach_strpart(dev->symlink, " ", pos, len) {
- strnfieldcpy(linkname, dev->symlink + pos, len+1);
+ strnfieldcpy(linkname, pos, len+1);
strfieldcpy(filename, udev_root);
strfieldcat(filename, linkname);
dbg("symlink '%s' to node '%s' requested", filename, dev->name);
===== udev-remove.c 1.23 vs edited =====
--- 1.23/udev-remove.c Wed Mar 3 05:43:18 2004
+++ edited/udev-remove.c Thu Mar 4 03:28:30 2004
@@ -72,7 +72,8 @@
char partitionname[NAME_SIZE];
int retval;
int i;
- int pos, len;
+ char *pos;
+ int len;
strfieldcpy(filename, udev_root);
strfieldcat(filename, dev->name);
@@ -102,7 +103,7 @@
delete_path(filename);
foreach_strpart(dev->symlink, " ", pos, len) {
- strnfieldcpy(linkname, dev->symlink + pos, len+1);
+ strnfieldcpy(linkname, pos, len+1);
strfieldcpy(filename, udev_root);
strfieldcat(filename, linkname);
===== udev.h 1.49 vs edited =====
--- 1.49/udev.h Wed Mar 3 05:39:01 2004
+++ edited/udev.h Thu Mar 4 03:26:20 2004
@@ -98,9 +98,9 @@
} while (0)
#define foreach_strpart(str, separator, pos, len) \
- for(pos = 0, len = strcspn(str, separator); \
- (pos) < strlen(str); \
- pos = pos + (len) + 1, len = strcspn((str) + pos, separator)) \
+ for(pos = str, len = 0; \
+ (pos) < ((str) + strlen(str)); \
+ pos = pos + len + strspn(pos, separator), len = strcspn(pos, separator)) \
if (len > 0)
static inline char *get_action(void)
===== udevdb.c 1.25 vs edited =====
--- 1.25/udevdb.c Wed Mar 3 06:33:03 2004
+++ edited/udevdb.c Thu Mar 4 03:33:07 2004
@@ -179,7 +179,8 @@
static int find_device_by_name(char *path, struct udevice *dev)
{
- int pos, len;
+ char *pos;
+ int len;
if (strncmp(dev->name, find_name, sizeof(dev->name)) == 0) {
memcpy(find_dev, dev, sizeof(struct udevice));
@@ -190,7 +191,7 @@
}
/* look for matching symlink*/
foreach_strpart(dev->symlink, " ", pos, len) {
- if (strncmp(&dev->symlink[pos], find_name, len) != 0)
+ if (strncmp(pos, find_name, len) != 0)
continue;
if (len != strlen(find_name))
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH] fix NAME="foo-%c{N}" gets a truncated name
2004-03-03 22:43 [PATCH] fix NAME="foo-%c{N}" gets a truncated name Patrick Mansfield
` (5 preceding siblings ...)
2004-03-04 3:09 ` Kay Sievers
@ 2004-03-04 18:57 ` Greg KH
6 siblings, 0 replies; 8+ messages in thread
From: Greg KH @ 2004-03-04 18:57 UTC (permalink / raw)
To: linux-hotplug
On Thu, Mar 04, 2004 at 04:09:51AM +0100, Kay Sievers wrote:
> On Wed, Mar 03, 2004 at 04:56:34PM -0800, Greg KH wrote:
> > On Wed, Mar 03, 2004 at 03:57:04PM -0800, Patrick Mansfield wrote:
> > >
> > > Here is a patch for some new tests.
> >
> > Applied, thanks.
>
> Here is a small improvement, which looks much better.
>
> Hey Pat, thanks a lot for finding the recent bug, hope this one will
> not break it again :)
Applied, thanks.
greg k-h
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id\x1470&alloc_id638&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 8+ messages in thread