Changeset e70f1ae in mainline for uspace/app/bdsh/exec.c


Ignore:
Timestamp:
2018-12-29T20:09:49Z (5 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Parents:
96e9434
Message:

Preventing find_command() to find cmds without a './' prefix

This commit fixes #684. The original implementation of find_command()
will find cmd inside the working directory even without
the prefix './'. However, those cmds would have not been visible in
the auto completion. This commit prevents this from happening.

The problem can be traced back to vfs_absolutize() which treats paths
without the './' prefix as relative paths. The changes made unsures
that only relative or absolute pathes will be passed to vfs_absolutize()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/exec.c

    r96e9434 re70f1ae  
    6666
    6767/** Returns the full path of "cmd" if cmd is found
    68  *
    69  * else just hand back cmd as it was presented
     68 * or null if the cmd cannot be found
    7069 */
    7170static char *find_command(char *cmd)
     
    7473
    7574        /* The user has specified a full or relative path, just give it back. */
    76         if (-1 != try_access(cmd)) {
    77                 return str_dup(cmd);
     75        size_t len = str_length(cmd);
     76        if ((len > 1 && cmd[0] == '/') || (len > 2 && cmd[0] == '.' && cmd[1] == '/')) {
     77                if (-1 != try_access(cmd)) {
     78                        return str_dup(cmd);
     79                }
    7880        }
    7981
     
    8991        free(found);
    9092
    91         /* We didn't find it, just give it back as-is. */
    92         return str_dup(cmd);
     93        /* We didn't find it, return NULL */
     94        return NULL;
    9395}
    9496
     
    105107
    106108        tmp = find_command(cmd);
     109        if (tmp == NULL) {
     110                cli_error(CL_EEXEC, "%s: Command not found '%s'", progname, cmd);
     111                return 1;
     112        }
    107113
    108114        files[0] = io->stdin;
Note: See TracChangeset for help on using the changeset viewer.