Skip to content

Commit

Permalink
plugins/semgrep: retrieve chroot root path by using mock.mock_root
Browse files Browse the repository at this point in the history
…directly
  • Loading branch information
rhyw committed Mar 7, 2024
1 parent 2f274c4 commit 8dbfa60
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions py/plugins/semgrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,9 @@ def scan_hook(results, mock, props):
semgrep_prefix = f"env PATH={semgrep_lib_dir}/bin:$PATH PYTHONPATH={semgrep_lib_dir}"
# assuming semgrep rules are located under the 'rules' directory
semgrep_rules_dir = os.path.join(results.tmpdir, "semgrep_rules/rules")
# get the chroot root path
ec, output = results.get_cmd_output(mock.get_mock_cmd(["--print-root-path"]), shell=False)
if ec != 0:
results.error("semgrep: failed to get chroot root path", ec=ec)
chroot_root_path = output.rstrip("/\n")
# write the chroot root path to the SEMGREP_SCAN_CHROOT_ROOT_PATH
with open(f"{chroot_root_path}{SEMGREP_SCAN_CHROOT_ROOT_PATH}", "w", encoding="utf-8") as f:
f.write(chroot_root_path)
with open(f"{mock.mock_root}{SEMGREP_SCAN_CHROOT_ROOT_PATH}", "w", encoding="utf-8") as f:
f.write(mock.mock_root)

# command to run semgrep scan
semgrep_scan_cmd = semgrep_prefix + (
Expand All @@ -166,8 +161,8 @@ def scan_hook(results, mock, props):

# eventually append the target directory to be scanned
semgrep_scan_cmd += (
f" --output={chroot_root_path}{SEMGREP_SCAN_OUTPUT} {chroot_root_path}{SEMGREP_SCAN_DIR}"
f" 2>{chroot_root_path}{SEMGREP_SCAN_LOG}"
f" --output={mock.mock_root}{SEMGREP_SCAN_OUTPUT} {mock.mock_root}{SEMGREP_SCAN_DIR}"
f" 2>{mock.mock_root}{SEMGREP_SCAN_LOG}"
)
# run semgrep scan
ec = results.exec_cmd(semgrep_scan_cmd, shell=True)
Expand Down

0 comments on commit 8dbfa60

Please sign in to comment.