DynamoRIO / DynamoRIO/dynamorio

drrun should imitate a shell when searching for the app

Open
#2,109 1 comment 0 reactions 0 assignees View on GitHub
Component-UI Usability
Dominant language
C
Stars
3.2k
Forks
629
Avg merge
2d 18h
Merged PRs (30d)
30

Description

On Unix, it should work thus:

If "app" contains '/', then try to use that filepath, which could be absolute or relative. Do not search in any other directories. Do not try adding any suffixes.

Otherwise, if the environment variable PATH is defined and not the empty string, split it into components, using ':', and try prefixing each in turn, with a '/' if the component is non-empty, so an empty component is treated as the current directory. Use stat() to check whether the resulting filepath refers to an executable ordinary file. (There are some complications here involving "owner", "group" and "other". We look at only one of those three. Which we look at depends who we are and who owns the file.) If the filepath is not an ordinary executable file, try the next component. If no executable ordinary file is found this way, give an error. Do not try in the current directory if the current directory was not on the PATH. Do not try adding any suffixes.

Otherwise, give an error. It is not worth trying to do anything clever if PATH is undefined or set to the empty string.

Some possible test cases:

```
mkdir t
cd t

umask 0002
mkdir a b c

touch a/x.exe b/x.exe c/x.exe x.exe
chmod +x a/x.exe b/x.exe c/x.exe x.exe

../bin64/drrun -- ./x.exe
# .../t/x.exe ... Failed to read app ELF headers.

../bin64/drrun -- ./x
# Failed to create process for ...

PATH=.:`pwd`: ../bin64/drrun -- x
# drrun: x: command not found

mkdir a/x
touch b/x c/x x
chmod +x x

PATH=a:b:c ../bin64/drrun -- x
# drrun: x: command not found

PATH=:a:b:c ../bin64/drrun -- x
# .../t/x ... Failed to read app ELF headers.

PATH=a::b:c ../bin64/drrun -- x
# .../t/x ... Failed to read app ELF headers.

PATH=a:b:c: ../bin64/drrun -- x
# .../t/x ... Failed to read app ELF headers.

chmod +x c/x

PATH=a:b:c ../bin64/drrun -- x
# .../t/c/x ... Failed to read app ELF headers.

PATH= ../bin64/drrun -- ./x
# .../t/x ... Failed to read app ELF headers.

PATH= ../bin64/drrun -- x
# Error: PATH is not set

chmod a+x b/x
sudo chown root:root b/x

PATH=a:b:c ../bin64/drrun -- x
# .../t/b/x .. Failed to read app ELF headers.

sudo chmod u-x b/x

PATH=a:b:c ../bin64/drrun -- x
# .../t/b/x .. Failed to read app ELF headers.

PATH=a:b:c sudo ../bin64/drrun -- x
# drrun: x: command not found
```

Contributor guide

Open the contributing guide

Research direction

Start at drrun's application lookup entry point and reproduce the Unix command examples in the issue, including PATH handling, slash-containing names, executable checks, and ownership cases. Done means drrun follows the specified shell-search behavior and reports the listed errors when no executable ordinary file is found.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
cli, operating-systems
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.