https://github.com/python/cpython/commit/ef5569e03dc774a3c214bce7659c4075af429400
commit: ef5569e03dc774a3c214bce7659c4075af429400
branch: 3.15
author: Miss Islington (bot) <[email protected]>
committer: vstinner <[email protected]>
date: 2026-07-09T21:15:51Z
summary:

[3.15] gh-98894: Quote test_dtrace tracer subcommands (GH-152901) (#153459)

gh-98894: Quote test_dtrace tracer subcommands (GH-152901)

Use shlex.join() when building tracer -c command strings
for avoiding issues with spaces.
(cherry picked from commit a159c6851f47549d2bc0cd37a0f555951bb11d7b)

Co-authored-by: stratakis <[email protected]>

files:
M Lib/test/test_dtrace.py

diff --git a/Lib/test/test_dtrace.py b/Lib/test/test_dtrace.py
index e1662a70b26d3e..30731b8f90ac14 100644
--- a/Lib/test/test_dtrace.py
+++ b/Lib/test/test_dtrace.py
@@ -1,6 +1,7 @@
 import dis
 import os.path
 import re
+import shlex
 import signal
 import subprocess
 import sys
@@ -92,7 +93,7 @@ def run_readelf(cmd):
 
     if proc.returncode:
         raise AssertionError(
-            f"Command {' '.join(cmd)!r} failed "
+            f"Command {shlex.join(cmd)!r} failed "
             f"with exit code {proc.returncode}: "
             f"stdout={stdout!r} stderr={stderr!r}"
         )
@@ -139,7 +140,7 @@ def trace(self, script_file, subcommand=None, *, 
timeout=None,
             raise
         if check_returncode and proc.returncode:
             raise AssertionError(
-                f"Command {' '.join(command)!r} failed "
+                f"Command {shlex.join(command)!r} failed "
                 f"with exit code {proc.returncode}: output={stdout!r}"
             )
         return stdout
@@ -148,7 +149,7 @@ def trace_python(self, script_file, python_file, 
optimize_python=None):
         python_flags = []
         if optimize_python:
             python_flags.extend(["-O"] * optimize_python)
-        subcommand = " ".join([sys.executable] + python_flags + [python_file])
+        subcommand = shlex.join([sys.executable] + python_flags + 
[python_file])
         return self.trace(script_file, subcommand, timeout=60,
                           check_returncode=True)
 
@@ -276,7 +277,7 @@ def run_case(self, name, optimize_python=None):
 
         try:
             proc = create_process_group(
-                ["bpftrace", "-e", program, "-c", " ".join(subcommand)],
+                ["bpftrace", "-e", program, "-c", shlex.join(subcommand)],
                 stdout=subprocess.PIPE,
                 stderr=subprocess.PIPE,
                 universal_newlines=True,
@@ -314,7 +315,8 @@ def assert_usable(self):
         program = f'usdt:{sys.executable}:python:function__entry {{ 
printf("probe: success\\n"); exit(); }}'
         try:
             proc = create_process_group(
-                ["bpftrace", "-e", program, "-c", f"{sys.executable} -c pass"],
+                ["bpftrace", "-e", program, "-c",
+                 shlex.join([sys.executable, "-c", "pass"])],
                 stdout=subprocess.PIPE,
                 stderr=subprocess.PIPE,
                 universal_newlines=True,

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to