From b484933b40632f7c4ee75a02272fb5b80f2839f3 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sat, 8 Dec 2018 10:59:56 +1030 Subject: [PATCH] plugin: simplify plugin dir test a little. Check if it's a normal file first, then check permissions. Signed-off-by: Rusty Russell --- lightningd/plugin.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lightningd/plugin.c b/lightningd/plugin.c index 57bd60792..b37fb932f 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -725,11 +725,11 @@ static const char *plugin_fullpath(const tal_t *ctx, const char *dir, fullname = path_join(ctx, dir, basename); if (stat(fullname, &st) != 0) return tal_free(fullname); - if (!(st.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)) || st.st_mode & S_IFDIR) + /* Only regular files please (or symlinks to such: stat not lstat!) */ + if ((st.st_mode & S_IFMT) != S_IFREG) return tal_free(fullname); - - /* Ignore directories, they have exec mode, but aren't executable. */ - if (st.st_mode & S_IFDIR) + /* Must be executable by someone. */ + if (!(st.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH))) return tal_free(fullname); return fullname; }