On 10 March 2011 03:18, Charles Lee <litt...@linux.vnet.ibm.com> wrote: > With a quick search in the SocketPermission using "cname =" as search word, > cname always seems to be lower cases. But hostname does not. It may need > some rework on the patch.
I think using String.regionMatches() [1] for the comparison (with 'ignoreCase' set to 'true') would solve the case-sensitivity problem. Please find attached an updated diff with how that would look. (Apols for not inlining it, I just know my current mail client would mangle it with line wrapping). > And more, every place where cname compare with another cname should use > normal equalsTo (equalsIgnoreCase is not needed). Every place where getName > and hostname is involved should use case-insensitive comparison. Any > opinion, Neil and Chris? >From a quick glance at the code, I think you're correct. However, I'd suggest making those improvements under a separate RFE, as they wouldn't directly relate to CR 7021280. Hope this helps, Neil [1] http://download.oracle.com/javase/6/docs/api/java/lang/String.html#regionMatches%28boolean,%20int,%20java.lang.String,%20int,%20int%29 -- Unless stated above: IBM email: neil_richards at uk.ibm.com IBM United Kingdom Limited - Registered in England and Wales with number 741598. Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU
diff --git a/src/share/classes/java/net/SocketPermission.java b/src/share/classes/java/net/SocketPermission.java --- a/src/share/classes/java/net/SocketPermission.java +++ b/src/share/classes/java/net/SocketPermission.java @@ -815,11 +815,15 @@ String thisHost = hostname; String thatHost = that.hostname; - if (thisHost == null) + if (thisHost == null) { return false; - else + } else if (wildcard) { + final int cnameLength = cname.length(); + return thatHost.regionMatches(true, + (thatHost.length() - cnameLength), cname, 0, cnameLength); + } else { return thisHost.equalsIgnoreCase(thatHost); - + } } /** * Checks two SocketPermission objects for equality.