-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4e22bb5
commit c9f38fb
Showing
5 changed files
with
11 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,5 @@ | ||
import os | ||
import shutil | ||
import subprocess | ||
|
||
__version__ = "0.9.5" | ||
|
||
STDPATH = os.pathsep.join(["/usr/bin", "/bin", "/usr/sbin", "/sbin"]) | ||
|
||
|
||
def safe_exec(binary_name: str, args: list) -> bytes: | ||
""" | ||
Executes the given binary with the given arguments as a subprocess. What makes this safe is that the binary name | ||
is not executed as an alias, and only binaries that live in trusted system locations are executed. This means that | ||
only system-wide binaries are executable. | ||
""" | ||
exec_path = shutil.which(binary_name, path=STDPATH) | ||
if exec_path is None: | ||
raise Exception(f"Could not find executable ${binary_name} in ${STDPATH}") | ||
|
||
args.insert(0, exec_path) | ||
return subprocess.check_output(args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters