Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 68009 - DNS-resolver bug in Java JDK
Summary: DNS-resolver bug in Java JDK
Status: RESOLVED WONTFIX
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Development (show other bugs)
Hardware: All Linux
: High critical (vote)
Assignee: Java team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-10-18 05:53 UTC by Kurt Huwig
Modified: 2006-02-08 19:12 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kurt Huwig 2004-10-18 05:53:59 UTC
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)

java version "1.4.2_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode)

A DESCRIPTION OF THE PROBLEM :
You cannot perform more than 32768 DNS lookups with one InitialDirContext. You get an error message about wrong ID. It is caused by the following bug:

In com/sun/jndi/dns/DnsClient.java, 'xid' is of type 'int' but initialized by the 'short' 'ident'. Thus if 'ident' reaches 32768, it becomes negative, rendering 'xid' negative to '-32768':

    private short ident = 0;		// used to set the msg ID field
[...]
	int xid;
	synchronized (identLock) {
	    xid = ++ident;
	}

In the class com/sun/jndi/dns/Header.java, the answer from the DNS server is converted backwards but to an 'int' instead of a 'short':

   private static int getShort(byte[] msg, int pos) {
	return (((msg[pos] & 0xFF) << 8) |
		(msg[pos + 1] & 0xFF));    }

So, the result of this method gives '32768' which is not equal to '-32768' and therefore the failure. A possible fix would be to replace

	    xid = getShort(msg, pos);
by
	    xid = (short) getShort(msg, pos);

in com/sun/jndi/dns/Header.java.

Reproducible: Always
Steps to Reproduce:
Compile and run this application:

---------- BEGIN SOURCE ----------
import java.util.*;

import javax.naming.directory.*;

public class DNSLookupBug {
    public static void main(String[] args) {
        try {
            final Hashtable env = new Hashtable();
            env.put("java.naming.factory.initial",
                    "com.sun.jndi.dns.DnsContextFactory");
            
            DirContext dnsContext = new InitialDirContext(env);
            
            final String[] domain = new String[] {"A"};
            for (int i = 0; i < 0xffff; i++) {
                dnsContext.getAttributes("sun.com", domain);
                if (i % 1000 == 0) {
                    // use this as a workaround
                    //dnsContext = new InitialDirContext(env);
                    System.out.println(i);
                }
            }
            
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

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


Actual Results:  
0
1000
2000
[...]
31000
32000
javax.naming.CommunicationException: DNS error: ID doesn't match; remaining name
'sun.com'
	at com.sun.jndi.dns.DnsClient.checkHeader(DnsClient.java:426)
	at com.sun.jndi.dns.DnsClient.query(DnsClient.java:162)
	at com.sun.jndi.dns.Resolver.query(Resolver.java:63)
	at com.sun.jndi.dns.DnsContext.c_getAttributes(DnsContext.java:410)
	at
com.sun.jndi.toolkit.ctx.ComponentDirContext.p_getAttributes(ComponentDirContext.java:213)
	at
com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:121)
	at
com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.getAttributes(PartialCompositeDirContext.java:109)
	at
javax.naming.directory.InitialDirContext.getAttributes(InitialDirContext.java:121)
	at DNSLookupBug.main(DNSLookupBug.java:17)

This error message is from 1.4.2; 1.5.0 gives a similar message with a socket
timeout.


Expected Results:  
0
1000
2000
3000
[...]
65000

Workaround: use new InitialDirContext before you reach the limit of 32768 requests

I reported the bug to Sun but did not receive an answer yet. Still as Gentoo
allowes to compiles the JDK itself, this bug can be fixed for the
JDK-source-ebuilds.
Comment 1 Karl Trygve Kalleberg (RETIRED) gentoo-dev 2004-12-18 13:31:38 UTC
The sun-j2sdk ebuild has proved to be extremely troublesome to maintain, so we've put it on the backburner for now, in order to deal with the more important bugs.

If you have the opportunity to come up with a patch, we can always squeeze it in, but we don't have the time to create one ourselves, I'm afraid.

Please reopen bug with a patch, otherwise we'll hopefully get to it at a later occasion. 

Sorry.
Comment 2 Josh Nichols (RETIRED) gentoo-dev 2006-02-08 19:11:51 UTC
Reopening in order to mark WONTFIX
Comment 3 Josh Nichols (RETIRED) gentoo-dev 2006-02-08 19:12:30 UTC
We no longer carry sun-j2sdk.