From 6b656c42c369dda78fde3a98aae6504e0e1613b5 Mon Sep 17 00:00:00 2001 From: Bartosz Malkowski Date: Mon, 19 Oct 2015 19:31:50 +0200 Subject: [PATCH] Bug #3623: NPE in tigase.jaxmpp.j2se.connectors.socket.HostnameVerifier fix: potential NPE in verifyIP() method --- .../socket/DefaultHostnameVerifier.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/jaxmpp-j2se/src/main/java/tigase/jaxmpp/j2se/connectors/socket/DefaultHostnameVerifier.java b/jaxmpp-j2se/src/main/java/tigase/jaxmpp/j2se/connectors/socket/DefaultHostnameVerifier.java index 0e186126..acc3588d 100644 --- a/jaxmpp-j2se/src/main/java/tigase/jaxmpp/j2se/connectors/socket/DefaultHostnameVerifier.java +++ b/jaxmpp-j2se/src/main/java/tigase/jaxmpp/j2se/connectors/socket/DefaultHostnameVerifier.java @@ -133,15 +133,17 @@ protected boolean verifyIp(String ipAddr, X509Certificate x509Certificate) throw log.warning("Certificate is NULL! Can't validate hostname."); return false; } - for (List entry : x509Certificate.getSubjectAlternativeNames()) { - Integer altNameType = (Integer) entry.get(0); - if (altNameType != 7) - continue; - String altName = (String) entry.get(1); - if (ipAddr.equalsIgnoreCase(altName)) { - return true; + final Collection> subjectAlternativeNames = x509Certificate.getSubjectAlternativeNames(); + if (subjectAlternativeNames != null) + for (List entry : x509Certificate.getSubjectAlternativeNames()) { + Integer altNameType = (Integer) entry.get(0); + if (altNameType != 7) + continue; + String altName = (String) entry.get(1); + if (ipAddr.equalsIgnoreCase(altName)) { + return true; + } } - } return false; }