Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions vmms/localDocker.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def getImages(self):
function is a lot of parsing and so can break easily.
"""
result = set()
cmd = "docker images"
cmd = "docker images --format 'table {{.Repository}}'"
o = subprocess.check_output(cmd, shell=True).decode("utf-8")
o_l = o.split("\n")
o_l.pop()
Expand All @@ -282,7 +282,7 @@ def getPartialOutput(self, vm):
config.Config.MAX_OUTPUT_FILE_SIZE,
)
output = subprocess.check_output(
cmd, stderr=subprocess.STDOUT, shell=True
cmd, stderr=subprocess.STDOUT, shell=True, timeout=30
).decode("utf-8")
Comment on lines 284 to 286
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Handle subprocess.TimeoutExpired exception.

The timeout=30 parameter will cause subprocess.check_output to raise subprocess.TimeoutExpired if the command exceeds 30 seconds. Without handling this exception, the function will propagate an unhandled exception to callers, potentially causing unexpected failures.

🐛 Proposed fix to handle timeout exception
+        try:
             output = subprocess.check_output(
                 cmd, stderr=subprocess.STDOUT, shell=True, timeout=30
             ).decode("utf-8")
+        except subprocess.TimeoutExpired:
+            self.log.warning("Timeout getting partial output for %s" % instanceName)
+            output = ""
+        except subprocess.CalledProcessError as e:
+            self.log.warning("Failed to get partial output for %s: %s" % (instanceName, e))
+            output = ""

         return output
🧰 Tools
🪛 Ruff (0.14.11)

284-284: subprocess call with shell=True identified, security issue

(S602)

🤖 Prompt for AI Agents
In `@vmms/localDocker.py` around lines 284 - 286, The call to
subprocess.check_output(..., timeout=30) assigned to output can raise
subprocess.TimeoutExpired; wrap that call in a try/except that catches
subprocess.TimeoutExpired and handles it gracefully (e.g., log the timeout with
context, include the cmd and timeout value, and either raise a controlled
exception or return a sensible error/result), ensuring the handler uses the same
cmd and timeout=30 information so callers don't get an unhandled exception from
subprocess.check_output.


return output
Loading