Skip to content

Commit 514c2ef

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> (cherry picked from commit 7ada4ad) Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com> Conflicts: utils/src/com/cloud/utils/net/NetUtils.java
1 parent 435fa22 commit 514c2ef

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,16 @@ public static String getDefaultHostIp() {
195195
return null;
196196
}
197197

198-
String[] info = NetUtils.getNetworkParams(nic);
199-
return info[0];
198+
String[] info = null;
199+
try {
200+
info = NetUtils.getNetworkParams(nic);
201+
} catch (NullPointerException ignored) {
202+
s_logger.debug("Caught NullPointerException when trying to getDefaultHostIp");
203+
}
204+
if (info != null) {
205+
return info[0];
206+
}
207+
return null;
200208
}
201209
}
202210

0 commit comments

Comments
 (0)