Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 4 additions & 4 deletions python/lib/cloudutils/configFileOps.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ def save(self):
for entry in self.entries:
if entry.op == "add":
if entry.separator == "=":
matchString = "^\ *" + entry.name + ".*"
matchString = r"^\ *" + entry.name + ".*"
elif entry.separator == " ":
matchString = "^\ *" + entry.name + "\ *" + entry.value
matchString = r"^\ *" + entry.name + r"\ *" + entry.value
else:
if entry.separator == "=":
matchString = "^\ *" + entry.name + "\ *=\ *" + entry.value
matchString = r"^\ *" + entry.name + r"\ *=\ *" + entry.value
else:
matchString = "^\ *" + entry.name + "\ *" + entry.value
matchString = r"^\ *" + entry.name + r"\ *" + entry.value
Comment on lines +71 to +78
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

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

These regexes should use \s* (or \s+) for whitespace and escape dynamic components to prevent unintended regex metacharacter interpretation. Example: name = re.escape(entry.name); value = re.escape(entry.value); then build patterns with r'^\s*' + name + r'\s*=\s*' + value (or r'^\s*' + name + r'\s+' + value). Also, r'\ *' is unusual; prefer clear whitespace classes.

Copilot uses AI. Check for mistakes.

match = re.match(matchString, line)
if match is not None:
Expand Down
13 changes: 8 additions & 5 deletions python/lib/cloudutils/networkConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ def getDefaultNetwork():
if not cmd.isSuccess():
logging.debug("Failed to get default route")
raise CloudRuntimeException("Failed to get default route")

result = cmd.getStdout().split(" ")
output = cmd.getStdout().strip()
result = output.split(" ")
if len(result) < 2:
logging.debug("Output for the default route incomplete: %s. It should have been '<GATEWAY> <DEVICE>'" % output)
raise CloudRuntimeException("Output for the default route incomplete")
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

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

The raised exception lacks context for troubleshooting. Consider including the actual output and the expected format in the exception message, e.g., raise CloudRuntimeException("Output for the default route incomplete: '%s' (expected ' ')" % output).

Suggested change
raise CloudRuntimeException("Output for the default route incomplete")
raise CloudRuntimeException("Output for the default route incomplete: '%s' (expected '<GATEWAY> <DEVICE>')" % output)

Copilot uses AI. Check for mistakes.
gateway = result[0]
dev = result[1]

Comment on lines +48 to 55
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

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

Splitting by a literal space can yield empty tokens when the output contains multiple spaces or tabs (common in shell output), causing dev to become an empty string despite len(result) >= 2. Use whitespace splitting to normalize tokens, e.g., parts = output.split(), then gateway = parts[0], dev = parts[1], or use a regex like m = re.match(r'(\S+)\s+(\S+)', output).

Copilot uses AI. Check for mistakes.
Expand Down Expand Up @@ -150,10 +153,10 @@ def getDevInfo(dev):
if line.find("HWaddr") != -1:
macAddr = line.split("HWaddr ")[1].strip(" ")
elif line.find("inet ") != -1:
m = re.search("addr:(.*)\ *Bcast:(.*)\ *Mask:(.*)", line)
m = re.search(r"addr:([^\s]+)\s*Bcast:([^\s]+)\s*Mask:([^\s]+)", line)
Copy link
Member

Choose a reason for hiding this comment

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

this does not work on either ubuntu or rocky/ol

the line looks like

        inet 10.0.34.xxx  netmask 255.255.240.0  broadcast 10.0.47.255

we can fix it later

if m is not None:
ipAddr = m.group(1).rstrip(" ")
netmask = m.group(3).rstrip(" ")
ipAddr = m.group(1).strip()
netmask = m.group(3).strip()

if networkConfig.isBridgePort(dev):
type = "brport"
Expand Down
Loading