United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7155051 DNS provider may return incorrect results
JDK-7155051 : DNS provider may return incorrect results

Details
Type:
Bug
Submit Date:
2012-03-20
Status:
Closed
Updated Date:
2013-04-20
Project Name:
JDK
Resolved Date:
2012-05-07
Component:
core-libs
OS:
generic
Sub-Component:
javax.naming
CPU:
generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
6u24
Fixed Versions:

Related Reports
Backport:
Backport:

Sub Tasks

Description
FULL PRODUCT VERSION :
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) Server VM (build 19.1-b02, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
SunOS nms-cricket 5.10 Generic_141414-01 sun4u sparc SUNW,Sun-Fire-V210

A DESCRIPTION OF THE PROBLEM :
The DNS provider attempts to check the XID of the response to make sure the response received from the server matches the requested XID.  If the response's XID does not match, the DNS provider caches the response in case another thread needs it.  However, the response is cached with the incorrect XID.  Therefore, when the lookup code continues, the current request receives an incorrect response.

I have included a patch that will correct the problem.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a new JNDI context that uses the DNS provider.  Attempt to do a a ctxt.getAttributes() using this context.  If multiple threads are involved, the results from the lookup can be incorrect.  This has a tendency to occur more frequently if the com.sun.jndi.dns.timeout.initial value is particularly low.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The expected result is to get the correct answer from the DNS lookup.
ACTUAL -
The lookup result may contain the answer from another query occurring from another thread.

REPRODUCIBILITY :
This bug can be reproduced occasionally.

---------- BEGIN SOURCE ----------
This can be reproduced with the standard usage of JNDI DNS provider.  I will include the diff that will correct this in the Workaround section.


---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
--- j2se/src/share/classes/com/sun/jndi/dns/DnsClient.java.orig 2011-08-20 14:06:55.000000000 -0400
+++ j2se/src/share/classes/com/sun/jndi/dns/DnsClient.java      2011-08-20 14:07:13.000000000 -0400
@@ -560,8 +560,8 @@ public class DnsClient {
        // enqueue only the first response, responses for retries are ignored.
        //
         synchronized (queuesLock) {
-           if (reqs.contains(xid)) { // enqueue only the first response
-               resps.put(xid, pkt);
+           if (reqs.contains(hdr.xid)) { // enqueue only the first response
+               resps.put(hdr.xid, pkt);
            }
         }

                                    

Comments
EVALUATION

Fix as suggestion in the description
                                     
2012-03-20



Hardware and Software, Engineered to Work Together