From 3db7fa27027110fde92a1b6061fab434fe708e9f Mon Sep 17 00:00:00 2001 From: "kay.sievers@vrfy.org" Date: Tue, 14 Sep 2004 17:45:48 -0700 Subject: [PATCH] [PATCH] fix udev segfaults with bad permissions file 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 | 16 ++++++---------- test/udev-test.pl | 16 ++++++++++++++++ udev_config.c | 8 +++----- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/namedev_parse.c b/namedev_parse.c index 4bb1a97ce..7e3783320 100644 --- a/namedev_parse.c +++ b/namedev_parse.c @@ -182,15 +182,13 @@ static int namedev_parse_rules(char *filename) 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(char *filename) 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) diff --git a/test/udev-test.pl b/test/udev-test.pl index 1e7c51e55..9feb28a7b 100644 --- a/test/udev-test.pl +++ b/test/udev-test.pl @@ -158,6 +158,22 @@ EOF # 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 => < 0) && isspace(bufline[0])) { bufline++; count--; } + if (count == 0) + continue; /* see if this is a comment */ if (bufline[0] == COMMENT_CHARACTER) -- 2.30.2