Skip to content

Commit

Permalink
results: fix quoting in handle_known_fp_list()
Browse files Browse the repository at this point in the history
... by using `shlex.quote()` from standard Python library.  This bug
caused regular expressions with parentheses to be interpreted by shell:
```
/bin/sh: -c: line 1: syntax error near unexpected token `('
```

Also avoid using the open-coded `shell_quote()` function from `util.py`
while printing shell commands in `exec_cmd()` because the function is
rather problematic and should be eventually unimplemented.

Unfortunately, we cannot easily nest `shlex.quote()` while combining
`mock --chroot ...` with `su -c ...` and the like because it results
in totally unreadable `scan.log`.

Resolves: https://issues.redhat.com/browse/OSH-617
  • Loading branch information
kdudka committed Aug 16, 2024
1 parent b08e972 commit a6997d0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions py/common/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import errno
import os
import re
import shlex
import shutil
import signal
import socket
Expand All @@ -30,7 +31,6 @@
import tempfile

# local imports
from csmock.common.util import shell_quote
from csmock.common.util import strlist_to_shell_cmd

CSGREP_FINAL_FILTER_ARGS = "--invert-match --event \"internal warning\" \
Expand Down Expand Up @@ -208,7 +208,7 @@ def exec_cmd(self, cmd, shell=False, echo=True):
self.handle_ec()
if echo:
if shell:
self.print_with_ts(shell_quote(cmd))
self.print_with_ts(cmd)
else:
self.print_with_ts(strlist_to_shell_cmd(cmd, escape_special=True))
try:
Expand Down Expand Up @@ -412,5 +412,5 @@ def handle_known_fp_list(props, results):
if len(path_re) == 0 or path_re.startswith("#"):
# skip comments and empty lines
continue
filter_cmd = f'csgrep --mode=json --invert-match --path="{shell_quote(path_re)}"'
filter_cmd = f'csgrep --mode=json --invert-match --path={shlex.quote(path_re)}'
props.result_filters += [filter_cmd]

0 comments on commit a6997d0

Please sign in to comment.