[jcifs] Problem with jcifs.UniAddress.isValidDnsName(String)
Michael B Allen
mba2000 at ioplex.com
Fri Oct 7 18:37:20 GMT 2005
On Fri, 7 Oct 2005 10:57:54 -0600
"Spierenburg, Peter" <peter.spierenburg at abridean.com> wrote:
> Greetings,
>
> It turns out that my regex is wrong at about a hundred different levels
> (check out RFC3696). For one thing, DNS names are not restricted to
> alphanumerics and the hyphen. In fact the dot is permitted as part of a
> label (properly escaped of course).
>
> I'm wondering if the method actually serves any purpose except to be
> broken. Its only reference is:
>
> if( isValidDnsName( hostname ) == false ) {
> throw new UnknownHostException( hostname );
> }
> addr = InetAddress.getByName( hostname );
>
> Consider that InetAddress.getByName(hostname) throws the same
> UnknownHostException as the 'if' statement, and is more effective at
> detecting invalid hostnames than any method call or regex. Could the
> method and call be removed entirely?
Clearly this check is designed to subvert the DNS lookup because
it may *succeed* and then the resolver will not try the next lookup
method. Unfortunately I don't understand the code comment and I don't
recall what the original problem was.
Mike
>
> Peter.
>
> -----Original Message-----
> From: jcifs-bounces+peter.spierenburg=abridean.com at lists.samba.org
> [mailto:jcifs-bounces+peter.spierenburg=abridean.com at lists.samba.org] On
> Behalf Of Tapperson Kevin
> Sent: Friday, October 07, 2005 11:26 AM
> To: jcifs at lists.samba.org
> Subject: RE: [jcifs] Problem with
> jcifs.UniAddress.isValidDnsName(String)
>
> I think the issue with java.util.regex.* here is that it was introduced
> in Java 1.4.
>
> I would venture to guess that there are still many users that run jcifs
> on the Java 1.3.x platform. (I know we do.)
>
>
> -----Original Message-----
> From: jcifs-bounces+kevin.tapperson=hcahealthcare.com at lists.samba.org
> [mailto:jcifs-bounces+kevin.tapperson=hcahealthcare.com at lists.samba.org]
> On Behalf Of Spierenburg, Peter
> Sent: Friday, October 07, 2005 8:26 AM
> To: Michael B Allen
> Cc: jcifs at lists.samba.org
> Subject: RE: [jcifs] Problem with
> jcifs.UniAddress.isValidDnsName(String)
>
> Greetings,
>
> Forgive me for being obtuse, but I'm not exactly sure what overkill and
> unique mean in this context. Would you mind clarifying?
>
> Peter.
>
> -----Original Message-----
> From: Michael B Allen [mailto:mba2000 at ioplex.com]
> Sent: Thursday, October 06, 2005 9:09 PM
> To: Spierenburg, Peter
> Cc: jcifs at lists.samba.org
> Subject: Re: [jcifs] Problem with
> jcifs.UniAddress.isValidDnsName(String)
>
> Overkill and java.util.regex looks a little unique. Come up with
> something lightweight and I'll add patch it.
>
> On Thu, 6 Oct 2005 14:40:32 -0600
> "Spierenburg, Peter" <peter.spierenburg at abridean.com> wrote:
>
> > Greetings,
> >
> > There appears to be a bug in the
> > jcifs.UniAddress.isValidDnsName(String)
> > method. As it stands in the 1.2.5 release, this method rejects dns
> > names which begin with a digit. This is unfortunate since digits are
> > permitted first characters in dns names. As a result, I propose
> > changing the method to use a regular expression:
> >
> > import java.util.regex.Pattern;
> >
> > static boolean isValidDnsName( String hostname ) {
> > Pattern p =
> > Pattern.compile("[a-zA-Z0-9][a-zA-Z0-9\\055]*([\\056][a-zA-Z0-9][a-zA-
> > Z0
> > -9\055]*)*");
> > return p.matcher(hostname).matches(); }
> >
> > which I believe more accurately expresses the nature of dns names.
> >
> > Does this seem reasonable?
> >
> > Peter-Frank Spierenburg.
> >
> >
>
More information about the jcifs
mailing list