Copilot commented on code in PR #11800:
URL: https://github.com/apache/cloudstack/pull/11800#discussion_r3947001630


##########
utils/src/main/java/com/cloud/utils/net/NetUtils.java:
##########
@@ -306,7 +306,7 @@ public static String getDefaultEthDevice() {
             final String defDev = Script.runSimpleBashScript("/sbin/route -n 
get default 2> /dev/null | grep interface | awk '{print $2}'");
             return defDev;
         }
-        return Script.runSimpleBashScript("ip route show default 0.0.0.0/0 | 
head -1 | awk '{print $5}'");
+        return Script.runSimpleBashScript("ip -j a | jq -r '.[] | .addr_info | 
map(select(.local == \"'`ip -j r s default | jq -r '.[0] | .prefsrc'`'\")) | 
.[].label'");

Review Comment:
   The new shell pipeline likely breaks in practice and can return the wrong 
value:
   - The jq program is assembled with `\"` inside a single-quoted jq filter, so 
after command substitution it becomes `.local == \"<ip>\"`, which jq will not 
parse as a valid string comparison.
   - It derives the interface by matching `prefsrc` against `ip -j a`, but the 
default route JSON already contains the `dev` field and `prefsrc` may be 
missing; also `.[]...| .[].label` can emit multiple lines while this method 
expects a single device name.
   
   Consider querying the default route interface directly from `ip -j route` 
JSON (and defaulting to empty so runSimpleBashScript returns null). This also 
avoids the nested backticks and a second jq invocation.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to