commit:     0b435ddd834bd18254c4d3341acdebf0829921f5
Author:     Jakob Drexel <jake42 <AT> rommel <DOT> stw <DOT> uni-erlangen <DOT> 
de>
AuthorDate: Sun May  3 09:06:45 2015 +0000
Commit:     William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Mon May  4 14:54:51 2015 +0000
URL:        https://gitweb.gentoo.org/proj/openrc.git/commit/?id=0b435ddd

librc: Fix crash if the service name is the same as the including runlevel

If a service has the same name as the runlevel it is in, openrc will
crash on changing to such runlevel. It goes in a recursive madness and
eventually gets a SEGV while in snprintf (don't know why).

This fixes two errors:
1. ls_dir stats files not with full path -> stat always returns != 0
2. ls_dir adds files to list if stat failed

This fixes #53.

X-Gentoo-Bug: 537304
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=537304

 src/librc/librc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/librc/librc.c b/src/librc/librc.c
index 03448e7..8f04313 100644
--- a/src/librc/librc.c
+++ b/src/librc/librc.c
@@ -101,7 +101,9 @@ ls_dir(const char *dir, int options)
                                        continue;
                        }
                        if (options & LS_DIR) {
-                               if (stat(d->d_name, &buf) == 0 &&
+                               snprintf(file, sizeof(file), "%s/%s",
+                                   dir, d->d_name);
+                               if (stat(file, &buf) != 0 ||
                                    !S_ISDIR(buf.st_mode))
                                        continue;
                        }

Reply via email to