Skip to contentSkip to conversation

udev segfaults with bad permissions file

DISCUSSION Applied Loleslaw 3 participants 3 messages Sep 14, 2004

lore
Share & tools
lore

Loleslaw

author
#0 lore raw

Hi,
Since I started using udev-031 on my gentoo udevstart would just segfault (udev-030 worked). As it turned out I had a file in /etc/udev/permissions.d with a single space in one line. I've cleaned the file and it works all right, but I thought you could be interested.
I've traced it to function namedev_init_permissions in namedev_parse.c I don't know C well enough to suggest a patch.

Regards,
Marek

-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170 Project Admins to receive an Apple iPod Mini FREE for your judgement on who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 13. Go here: http://sf.net/ppc_contest.php
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#1 lore raw
Quoted 7 lines · Loleslaw

Hi,
Since I started using udev-031 on my gentoo udevstart would just segfault (udev-030 worked). As it turned out I had a file in /etc/udev/permissions.d with a single space in one line. I've cleaned the file and it works all right, but I thought you could be interested.
I've traced it to function namedev_init_permissions in namedev_parse.c I don't know C well enough to suggest a patch.

Yeah, thanks for pointing that out. It only happens if the file ends with whitespace-only lines. Here is a fix and a test for udev-test.pl to cover that case.

Thanks,
Kay

===== namedev_parse.c 1.35 vs edited =====

namedev_parse.c +6 -10
@@ -182,15 +182,13 @@ static int namedev_parse_rules(char *fil
 			continue;
 		}
 
-		/* empty line? */
-		if (bufline[0] == '\0' || bufline[0] == '\n')
-			continue;
-
 		/* eat the whitespace */
-		while (isspace(bufline[0])) {
+		while ((count > 0) && isspace(bufline[0])) {
 			bufline++;
 			count--;
 		}
+		if (count == 0)
+			continue;
 
 		/* see if this is a comment */
 		if (bufline[0] == COMMENT_CHARACTER)
@@ -381,15 +379,13 @@ static int namedev_parse_permissions(cha
 			continue;
 		}
 
-		/* empty line? */
-		if (bufline[0] == '\0' || bufline[0] == '\n')
-			continue;
-
 		/* eat the whitespace */
-		while (isspace(bufline[0])) {
+		while ((count > 0) && isspace(bufline[0])) {
 			bufline++;
 			count--;
 		}
+		if (count == 0)
+			continue;
 
 		/* see if this is a comment */
 		if (bufline[0] == COMMENT_CHARACTER)

===== udev_config.c 1.20 vs edited =====

udev_config.c +3 -5
@@ -161,15 +161,13 @@ static int parse_config_file(void)
 			continue;
 		}
 
-		/* empty line? */
-		if (bufline[0] == '\0' || bufline[0] == '\n')
-			continue;
-
 		/* eat the whitespace */
-		while (isspace(bufline[0])) {
+		while ((count > 0) && isspace(bufline[0])) {
 			bufline++;
 			count--;
 		}
+		if (count == 0)
+			continue;
 
 		/* see if this is a comment */
 		if (bufline[0] == COMMENT_CHARACTER)

===== test/udev-test.pl 1.56 vs edited =====

test/udev-test.pl +16 -0
@@ -161,6 +161,22 @@ KERNEL="ttyUSB0", NAME="visor"
 EOF
 	},
 	{
+		desc		=> "Handle whitespace only lines (and replace kernel name)",
+		subsys		=> "tty",
+		devpath		=> "/class/tty/ttyUSB0",
+		exp_name	=> "whitespace" ,
+		conf		=> <<EOF
+
+ 
+
+ # this is a comment with whitespace before the comment 
+KERNEL="ttyUSB0", NAME="whitespace"
+
+ 
+
+EOF
+	},
+	{
 		desc		=> "Handle empty lines in config file (and replace kernel name)",
 		subsys		=> "tty",
 		devpath		=> "/class/tty/ttyUSB0",
Applied
#2 lore raw
In reply to Loleslaw
Quoted 9 lines · Kay Sievers
Quoted 7 lines · Loleslaw

Hi,
Since I started using udev-031 on my gentoo udevstart would just segfault (udev-030 worked). As it turned out I had a file in /etc/udev/permissions.d with a single space in one line. I've cleaned the file and it works all right, but I thought you could be interested.
I've traced it to function namedev_init_permissions in namedev_parse.c I don't know C well enough to suggest a patch.

Quoted 3 lines

Yeah, thanks for pointing that out. It only happens if the file ends with whitespace-only lines. Here is a fix and a test for udev-test.pl to cover that case.

Applied, thanks.

greg k-h

-------------------------------------------------------
This SF.Net email is sponsored by: thawte's Crypto Challenge Vl Crack the code and win a Sony DCRHC40 MiniDV Digital Handycam Camcorder. More prizes in the weekly Lunch Hour Challenge. Sign up NOW http://ad.doubleclick.net/clk;10740251;10262165;m
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel