Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-4963

isIpLiteral check for server address resolution is incorrect

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 4.10.0
    • Affects Version/s: None
    • Component/s: Connection Management
    • None
    • Fully Compatible
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      As part of JAVA-4911, the InetAddressResolver interface was added, and, if configured, the driver is supposed to use it to resolve host names to IP addresses. However, it's not supposed to use it to if the address is an IP literal. To detect this, the driver makes the following check:

          // If this returns true, it's either an IP literal or a malformed hostname.  But either way, skip lookup via resolver
          private boolean isIpLiteral() {
              return getHost().charAt(0) == '[' || Character.digit(getHost().charAt(0), 16) != -1 || (getHost().charAt(0) == ':');
          }
      

      This check is incorrect, as it will treat any host name starting with the characters 'a' through 'f' as IP literals.

      Looking at the JDK source more closely, it's not such a simple check to see if a string is an IP literal, as it involves parsing the whole string, and there is also a system property, "jdk.net.allowAmbiguousIPAddressLiterals", which figures into the determination.

      But the check in the driver is wrong, so we either need to:

      1. Fully and properly implement the check for IP literals
      2. Delegate that determination to the configured InetAddressResolver.

      It was decided to implement the second option

            Assignee:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Reporter:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: