rc

[fork] interactive rc shell
Log | Files | Refs | README | LICENSE

commit 6fe8c0e92443ce3898fa8c3ebd73f6976fe98eec
parent cb99a1b11a2f0d39cd92a27351a4920422bcd7a1
Author: Toby Goodwin <toby@paganbooks.eu>
Date:   Sat, 28 Apr 2018 08:21:19 +0100

check access of external commands when completing

Diffstat:
Medit-readline.c | 16+++++++++++++++-
Mrc.h | 5++++-
Mwhich.c | 2+-
3 files changed, 20 insertions(+), 3 deletions(-)

diff --git 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); diff --git a/rc.h b/rc.h @@ -180,7 +180,6 @@ extern int lineno; /* builtins.c */ extern builtin_t *isbuiltin(char *); extern void b_exec(char **), funcall(char **), b_dot(char **), b_builtin(char **); -extern char *which(char *, bool); extern char *compl_builtin(const char *, int); /* except.c */ @@ -398,3 +397,7 @@ extern bool forked; /* walk.c */ extern bool walk(Node *, bool); extern bool cond; + +/* which.c */ +extern bool rc_access(char *, bool); +extern char *which(char *, bool); diff --git a/which.c b/which.c @@ -47,7 +47,7 @@ static int ingidset(gid_t g) { Returns a bool instead of this -1 nonsense. */ -static bool rc_access(char *path, bool verbose) { +bool rc_access(char *path, bool verbose) { struct stat st; int mask; if (stat(path, &st) != 0) {