Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #112

Merged
merged 3 commits into from
Dec 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions slitherin/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import os
import shutil
import pty
import sys
from pathlib import Path
import slitherin
from pkg_resources import iter_entry_points

SLITHERIN_VERSION = "0.5.0"
SLITHERIN_VERSION = "0.5.1"


def slitherin_detectors_list_as_arguments() -> str:
Expand Down Expand Up @@ -47,7 +48,34 @@ def run(
subprocess_cwd,
)

pty.spawn(cmd, read) # this allows to print continuously and with colors
master, slave = pty.openpty()

try:
process = subprocess.Popen(cmd, stdout=slave, stderr=slave, text=False)
os.close(slave)

while True:
try:
output = os.read(master, 1024)
except OSError as e:
if e.errno == 5: # Errno 5 corresponds to Input/output error
break
else:
raise
if not output:
break
decoded_output = output.decode(sys.stdout.encoding, errors="replace")
print(decoded_output, end="")

return_code = process.wait()
if return_code != 0:
raise Exception(
f"Errored out with code: {return_code}, while running slither"
)

except Exception as e:
print(f"Failed to run slither: {str(e)}")
raise e


def handle_list() -> None:
Expand All @@ -61,7 +89,11 @@ def handle_list() -> None:

def handle_parser(args: argparse.Namespace, slither_args) -> None:
slitherin_detectors = slitherin_detectors_list_as_arguments()
slither_with_args = ["slither"] + slither_args
slither_with_args = [
"slither",
"--fail-none",
] + slither_args # using fail-none flag, so slither will return 0 even though there are findings

if args.pess:
run(
slither_with_args + ["--detect", slitherin_detectors],
Expand Down