From 518c1454ceec785840cef26d8906a8fe7cf0ce1e Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Sat, 06 Jan 2007 23:25:24 +0000
Subject: [PATCH] Update the LDAP authentication handler to fix a potential null pointer exception that could be thrown if the connection to the server was lost between sending the bind request and getting the bind response.
---
opends/src/server/org/opends/server/messages/ToolMessages.java | 14 +++++++
opends/src/server/org/opends/server/tools/LDAPAuthenticationHandler.java | 89 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 103 insertions(+), 0 deletions(-)
diff --git a/opends/src/server/org/opends/server/messages/ToolMessages.java b/opends/src/server/org/opends/server/messages/ToolMessages.java
index 1be5637..e6a9b9b 100644
--- a/opends/src/server/org/opends/server/messages/ToolMessages.java
+++ b/opends/src/server/org/opends/server/messages/ToolMessages.java
@@ -7507,6 +7507,17 @@
/**
+ * The message ID for the message that will be used if the connection to the
+ * Directory Server is closed while attempting to read the bind response from
+ * the server. This does not take any arguments.
+ */
+ public static final int
+ MSGID_LDAPAUTH_CONNECTION_CLOSED_WITHOUT_BIND_RESPONSE =
+ CATEGORY_MASK_TOOLS | SEVERITY_MASK_SEVERE_ERROR | 789;
+
+
+
+ /**
* Associates a set of generic messages with the message IDs defined in this
* class.
*/
@@ -8030,6 +8041,9 @@
registerMessage(MSGID_LDAPAUTH_CANNOT_SEND_SIMPLE_BIND,
"Cannot send the simple bind request: %s.");
+ registerMessage(MSGID_LDAPAUTH_CONNECTION_CLOSED_WITHOUT_BIND_RESPONSE,
+ "The connection to the Directory Server was closed " +
+ "before the bind response could be read.");
registerMessage(MSGID_LDAPAUTH_CANNOT_READ_BIND_RESPONSE,
"Cannot read the bind response from the server: " +
"%s.");
diff --git a/opends/src/server/org/opends/server/tools/LDAPAuthenticationHandler.java b/opends/src/server/org/opends/server/tools/LDAPAuthenticationHandler.java
index 5fb4367..abb33a2 100644
--- a/opends/src/server/org/opends/server/tools/LDAPAuthenticationHandler.java
+++ b/opends/src/server/org/opends/server/tools/LDAPAuthenticationHandler.java
@@ -347,6 +347,14 @@
try
{
ASN1Element responseElement = reader.readElement();
+ if (responseElement == null)
+ {
+ int msgID = MSGID_LDAPAUTH_CONNECTION_CLOSED_WITHOUT_BIND_RESPONSE;
+ String message = getMessage(msgID);
+ throw new ClientException(LDAPResultCode.CLIENT_SIDE_SERVER_DOWN,
+ msgID, message);
+ }
+
responseMessage = LDAPMessage.decode(responseElement.decodeAsSequence());
}
catch (IOException ioe)
@@ -665,6 +673,14 @@
try
{
ASN1Element responseElement = reader.readElement();
+ if (responseElement == null)
+ {
+ int msgID = MSGID_LDAPAUTH_CONNECTION_CLOSED_WITHOUT_BIND_RESPONSE;
+ String message = getMessage(msgID);
+ throw new ClientException(LDAPResultCode.CLIENT_SIDE_SERVER_DOWN,
+ msgID, message);
+ }
+
responseMessage = LDAPMessage.decode(responseElement.decodeAsSequence());
}
catch (IOException ioe)
@@ -931,6 +947,14 @@
try
{
ASN1Element responseElement1 = reader.readElement();
+ if (responseElement1 == null)
+ {
+ int msgID = MSGID_LDAPAUTH_CONNECTION_CLOSED_WITHOUT_BIND_RESPONSE;
+ String message = getMessage(msgID);
+ throw new ClientException(LDAPResultCode.CLIENT_SIDE_SERVER_DOWN,
+ msgID, message);
+ }
+
responseMessage1 =
LDAPMessage.decode(responseElement1.decodeAsSequence());
}
@@ -1076,6 +1100,14 @@
try
{
ASN1Element responseElement = reader.readElement();
+ if (responseElement == null)
+ {
+ int msgID = MSGID_LDAPAUTH_CONNECTION_CLOSED_WITHOUT_BIND_RESPONSE;
+ String message = getMessage(msgID);
+ throw new ClientException(LDAPResultCode.CLIENT_SIDE_SERVER_DOWN,
+ msgID, message);
+ }
+
responseMessage2 = LDAPMessage.decode(responseElement.decodeAsSequence());
}
catch (IOException ioe)
@@ -1536,6 +1568,14 @@
try
{
ASN1Element responseElement1 = reader.readElement();
+ if (responseElement1 == null)
+ {
+ int msgID = MSGID_LDAPAUTH_CONNECTION_CLOSED_WITHOUT_BIND_RESPONSE;
+ String message = getMessage(msgID);
+ throw new ClientException(LDAPResultCode.CLIENT_SIDE_SERVER_DOWN,
+ msgID, message);
+ }
+
responseMessage1 =
LDAPMessage.decode(responseElement1.decodeAsSequence());
}
@@ -1850,6 +1890,14 @@
try
{
ASN1Element responseElement = reader.readElement();
+ if (responseElement == null)
+ {
+ int msgID = MSGID_LDAPAUTH_CONNECTION_CLOSED_WITHOUT_BIND_RESPONSE;
+ String message = getMessage(msgID);
+ throw new ClientException(LDAPResultCode.CLIENT_SIDE_SERVER_DOWN,
+ msgID, message);
+ }
+
responseMessage2 = LDAPMessage.decode(responseElement.decodeAsSequence());
}
catch (IOException ioe)
@@ -2523,6 +2571,14 @@
try
{
ASN1Element responseElement = reader.readElement();
+ if (responseElement == null)
+ {
+ int msgID = MSGID_LDAPAUTH_CONNECTION_CLOSED_WITHOUT_BIND_RESPONSE;
+ String message = getMessage(msgID);
+ throw new ClientException(LDAPResultCode.CLIENT_SIDE_SERVER_DOWN,
+ msgID, message);
+ }
+
responseMessage = LDAPMessage.decode(responseElement.decodeAsSequence());
}
catch (IOException ioe)
@@ -3139,6 +3195,14 @@
try
{
ASN1Element responseElement = reader.readElement();
+ if (responseElement == null)
+ {
+ int msgID = MSGID_LDAPAUTH_CONNECTION_CLOSED_WITHOUT_BIND_RESPONSE;
+ String message = getMessage(msgID);
+ throw new ClientException(LDAPResultCode.CLIENT_SIDE_SERVER_DOWN,
+ msgID, message);
+ }
+
responseMessage = LDAPMessage.decode(responseElement.decodeAsSequence());
}
catch (IOException ioe)
@@ -3371,6 +3435,14 @@
try
{
ASN1Element responseElement = reader.readElement();
+ if (responseElement == null)
+ {
+ int msgID = MSGID_LDAPAUTH_CONNECTION_CLOSED_WITHOUT_BIND_RESPONSE;
+ String message = getMessage(msgID);
+ throw new ClientException(LDAPResultCode.CLIENT_SIDE_SERVER_DOWN,
+ msgID, message);
+ }
+
responseMessage =
LDAPMessage.decode(responseElement.decodeAsSequence());
}
@@ -3549,6 +3621,15 @@
try
{
ASN1Element responseElement = reader.readElement();
+ if (responseElement == null)
+ {
+ int msgID =
+ MSGID_LDAPAUTH_CONNECTION_CLOSED_WITHOUT_BIND_RESPONSE;
+ String message = getMessage(msgID);
+ throw new ClientException(LDAPResultCode.CLIENT_SIDE_SERVER_DOWN,
+ msgID, message);
+ }
+
responseMessage =
LDAPMessage.decode(responseElement.decodeAsSequence());
}
@@ -3762,6 +3843,14 @@
try
{
ASN1Element responseElement = reader.readElement();
+ if (responseElement == null)
+ {
+ int msgID = MSGID_LDAPAUTH_CONNECTION_CLOSED_WITHOUT_BIND_RESPONSE;
+ String message = getMessage(msgID);
+ throw new ClientException(LDAPResultCode.CLIENT_SIDE_SERVER_DOWN,
+ msgID, message);
+ }
+
responseMessage = LDAPMessage.decode(responseElement.decodeAsSequence());
}
catch (IOException ioe)
--
Gitblit v1.10.0