11import dis
22import os .path
33import re
4+ import shlex
45import signal
56import subprocess
67import sys
@@ -92,7 +93,7 @@ def run_readelf(cmd):
9293
9394 if proc .returncode :
9495 raise AssertionError (
95- f"Command { ' ' .join (cmd )!r} failed "
96+ f"Command { shlex .join (cmd )!r} failed "
9697 f"with exit code { proc .returncode } : "
9798 f"stdout={ stdout !r} stderr={ stderr !r} "
9899 )
@@ -139,7 +140,7 @@ def trace(self, script_file, subcommand=None, *, timeout=None,
139140 raise
140141 if check_returncode and proc .returncode :
141142 raise AssertionError (
142- f"Command { ' ' .join (command )!r} failed "
143+ f"Command { shlex .join (command )!r} failed "
143144 f"with exit code { proc .returncode } : output={ stdout !r} "
144145 )
145146 return stdout
@@ -148,7 +149,7 @@ def trace_python(self, script_file, python_file, optimize_python=None):
148149 python_flags = []
149150 if optimize_python :
150151 python_flags .extend (["-O" ] * optimize_python )
151- subcommand = " " .join ([sys .executable ] + python_flags + [python_file ])
152+ subcommand = shlex .join ([sys .executable ] + python_flags + [python_file ])
152153 return self .trace (script_file , subcommand , timeout = 60 ,
153154 check_returncode = True )
154155
@@ -276,7 +277,7 @@ def run_case(self, name, optimize_python=None):
276277
277278 try :
278279 proc = create_process_group (
279- ["bpftrace" , "-e" , program , "-c" , " " .join (subcommand )],
280+ ["bpftrace" , "-e" , program , "-c" , shlex .join (subcommand )],
280281 stdout = subprocess .PIPE ,
281282 stderr = subprocess .PIPE ,
282283 universal_newlines = True ,
@@ -314,7 +315,8 @@ def assert_usable(self):
314315 program = f'usdt:{ sys .executable } :python:function__entry {{ printf("probe: success\\ n"); exit(); }}'
315316 try :
316317 proc = create_process_group (
317- ["bpftrace" , "-e" , program , "-c" , f"{ sys .executable } -c pass" ],
318+ ["bpftrace" , "-e" , program , "-c" ,
319+ shlex .join ([sys .executable , "-c" , "pass" ])],
318320 stdout = subprocess .PIPE ,
319321 stderr = subprocess .PIPE ,
320322 universal_newlines = True ,
0 commit comments