From 6fe8c0e92443ce3898fa8c3ebd73f6976fe98eec Mon Sep 17 00:00:00 2001 From: Toby Goodwin Date: Sat, 28 Apr 2018 08:21:19 +0100 Subject: check access of external commands when completing --- edit-readline.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'edit-readline.c') diff --git a/edit-readline.c b/edit-readline.c index 4a80044..bf7ff40 100644 --- a/edit-readline.c +++ b/edit-readline.c @@ -16,6 +16,19 @@ struct cookie { char *buffer; }; +/* can the name which we found in the first element of path be exec()d? */ +static bool is_command(List *path, char *name) { + char *full; + size_t len; + + len = strlen(path->w) + strlen(name) + 2; + full = nalloc(len); + strcpy(full, path->w); + strcat(full, "/"); + strcat(full, name); + return rc_access(full, FALSE); +} + static char *compl_extcmd(const char *text, int state) { static DIR *d; static List *path; @@ -32,7 +45,8 @@ static char *compl_extcmd(const char *text, int state) { else { struct dirent *e; while ((e = readdir(d))) { - if (strncmp(e->d_name, text, len) == 0) + if (strncmp(e->d_name, text, len) == 0 && + is_command(path, e->d_name)) return strdup(e->d_name); } closedir(d); -- cgit v1.2.3