diff options
| author | Toby Goodwin <toby@paganbooks.eu> | 2018-04-28 08:21:19 +0100 |
|---|---|---|
| committer | Toby Goodwin <toby@paganbooks.eu> | 2018-04-28 08:21:19 +0100 |
| commit | 6fe8c0e92443ce3898fa8c3ebd73f6976fe98eec (patch) | |
| tree | 453b2ee53f0d12caa4966dcb0fc7ac7770c49f06 /edit-readline.c | |
| parent | cb99a1b11a2f0d39cd92a27351a4920422bcd7a1 (diff) | |
check access of external commands when completing
Diffstat (limited to 'edit-readline.c')
| -rw-r--r-- | edit-readline.c | 16 |
1 files changed, 15 insertions, 1 deletions
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); |