Skip to content

Commit 7ada4ad

Browse files
committed
NetUtils: Check for NPE in getDefaultHostIp method when processing nic/mac
On hosts or containers where they don't have valid mac address on nic resulting in null, NetUtils.getNetworkParam can throw NPE. This was a case found on TravisCI where OpenVZ containers are used. This method (getDefaultHostIp) is used at several other places within the ACS codebase to get the host IP and if null is caught we fallback to localhost or 127.0.0.1, so we therefore set info to null before trying to process network param and if we fail we return null and expect other layers to use localhost. Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent e3b3a18 commit 7ada4ad

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

utils/src/com/cloud/utils/net/NetUtils.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,12 @@ public static String getDefaultHostIp() {
191191
return null;
192192
}
193193

194-
String[] info = NetUtils.getNetworkParams(nic);
194+
String[] info = null;
195+
try {
196+
info = NetUtils.getNetworkParams(nic);
197+
} catch (NullPointerException ignored) {
198+
s_logger.debug("Caught NullPointerException when trying to getDefaultHostIp");
199+
}
195200
if (info != null) {
196201
return info[0];
197202
}

0 commit comments

Comments
 (0)