(cmd)
| 34 | |
| 35 | |
| 36 | def _check_cmd(cmd): |
| 37 | # Use regex [a-zA-Z0-9./-]+: reject empty string, space, etc. |
| 38 | safe_chars = [] |
| 39 | for first, last in (("a", "z"), ("A", "Z"), ("0", "9")): |
| 40 | for ch in range(ord(first), ord(last) + 1): |
| 41 | safe_chars.append(chr(ch)) |
| 42 | safe_chars.append("./-") |
| 43 | safe_chars = ''.join(safe_chars) |
| 44 | |
| 45 | if isinstance(cmd, (tuple, list)): |
| 46 | check_strs = cmd |
| 47 | elif isinstance(cmd, str): |
| 48 | check_strs = [cmd] |
| 49 | else: |
| 50 | return False |
| 51 | |
| 52 | for arg in check_strs: |
| 53 | if not isinstance(arg, str): |
| 54 | return False |
| 55 | if not arg: |
| 56 | # reject empty string |
| 57 | return False |
| 58 | for ch in arg: |
| 59 | if ch not in safe_chars: |
| 60 | return False |
| 61 | |
| 62 | return True |
| 63 | |
| 64 | |
| 65 | # _aix_support used by distutil.util calls subprocess.check_output() |
no test coverage detected