chiark / gitweb /
[PATCH] fix udev segfaults with bad permissions file
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>
Wed, 15 Sep 2004 00:45:48 +0000 (17:45 -0700)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 04:37:01 +0000 (21:37 -0700)
On Tue, Sep 14, 2004 at 02:53:12PM +0200, Loleslaw wrote:
> 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.

namedev_parse.c
test/udev-test.pl
udev_config.c

index 4bb1a97ce9eb05bc3b8455f33f46b18e41a48b5d..7e3783320256818948a547d744e0062bd5fe3c2e 100644 (file)
@@ -182,15 +182,13 @@ static int namedev_parse_rules(char *filename)
                        continue;
                }
 
                        continue;
                }
 
-               /* empty line? */
-               if (bufline[0] == '\0' || bufline[0] == '\n')
-                       continue;
-
                /* eat the whitespace */
                /* eat the whitespace */
-               while (isspace(bufline[0])) {
+               while ((count > 0) && isspace(bufline[0])) {
                        bufline++;
                        count--;
                }
                        bufline++;
                        count--;
                }
+               if (count == 0)
+                       continue;
 
                /* see if this is a comment */
                if (bufline[0] == COMMENT_CHARACTER)
 
                /* see if this is a comment */
                if (bufline[0] == COMMENT_CHARACTER)
@@ -381,15 +379,13 @@ static int namedev_parse_permissions(char *filename)
                        continue;
                }
 
                        continue;
                }
 
-               /* empty line? */
-               if (bufline[0] == '\0' || bufline[0] == '\n')
-                       continue;
-
                /* eat the whitespace */
                /* eat the whitespace */
-               while (isspace(bufline[0])) {
+               while ((count > 0) && isspace(bufline[0])) {
                        bufline++;
                        count--;
                }
                        bufline++;
                        count--;
                }
+               if (count == 0)
+                       continue;
 
                /* see if this is a comment */
                if (bufline[0] == COMMENT_CHARACTER)
 
                /* see if this is a comment */
                if (bufline[0] == COMMENT_CHARACTER)
index 1e7c51e5565f2d700e3b8884d052d7b86c1653c6..9feb28a7ba1afc40650b88926bccdb7bd7bd5690 100644 (file)
@@ -158,6 +158,22 @@ EOF
  # this is a comment with whitespace before the comment 
 KERNEL="ttyUSB0", NAME="visor"
 
  # this is a comment with whitespace before the comment 
 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
        },
        {
 EOF
        },
        {
index 20b6c75d32604fa1fe4263e5fee07d5600541aa2..ba2b3d2b886966eaa890d09673e9a64a310e79c8 100644 (file)
@@ -161,15 +161,13 @@ static int parse_config_file(void)
                        continue;
                }
 
                        continue;
                }
 
-               /* empty line? */
-               if (bufline[0] == '\0' || bufline[0] == '\n')
-                       continue;
-
                /* eat the whitespace */
                /* eat the whitespace */
-               while (isspace(bufline[0])) {
+               while ((count > 0) && isspace(bufline[0])) {
                        bufline++;
                        count--;
                }
                        bufline++;
                        count--;
                }
+               if (count == 0)
+                       continue;
 
                /* see if this is a comment */
                if (bufline[0] == COMMENT_CHARACTER)
 
                /* see if this is a comment */
                if (bufline[0] == COMMENT_CHARACTER)