[kaffe] PATCH: CodeSource

Casey Marshall rsdio@metastatic.org
Fri Jan 23 23:59:01 2004


--=-=-=

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi.

The attached patch fixes a number of problems with
java.security.CodeSource when either the location or certificates
field is null. Some basic tests with my PolicyFile reader work with
this patch.

2004-01-23  Casey Marshall <rsdio@metastatic.org>

        * libraries/javalib/java/security/CodeSource.java
        (location): marked final.
        (certificates): marked final.
        (<init>): clone the certificate array.
        (getCertificates): clone the certificate array.
        (equals): handle null components.
        (hashCode): handle null components.
        (toString): handle null components.
        (implies): don't check SocketPermission if the host field of
        `location' is empty.

Cheers.

- -- 
Casey Marshall || rsdio@metastatic.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.7 <http://mailcrypt.sourceforge.net/>

iD8DBQFAEiTRgAuWMgRGsWsRAoLLAJ9xx4QB96ks8IpVC1aoUy5jNZdPmgCdGJM6
jbkBC9xxcAkMz8i/oZpCcXM=
=q0QS
-----END PGP SIGNATURE-----

--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment; filename=codesource.patch

Index: libraries/javalib/java/security/CodeSource.java
===================================================================
RCS file: /cvs/kaffe/kaffe/libraries/javalib/java/security/CodeSource.java,v
retrieving revision 1.4
diff -u -r1.4 CodeSource.java
--- libraries/javalib/java/security/CodeSource.java	18 May 2003 16:44:56 -0000	1.4
+++ libraries/javalib/java/security/CodeSource.java	24 Jan 2004 07:50:52 -0000
@@ -5,7 +5,7 @@
  * Copyright (c) 1999
  *	Archie L. Cobbs.  All rights reserved.
  * Copyright (c) 1999
- *	Transvirtual Technologies, Inc.  All rights reserved.
+ *	Transvirtual Technologies, Inc.	 All rights reserved.
  *
  * See the file "license.terms" for information on usage and redistribution
  * of this file.
@@ -24,12 +24,16 @@
 
 public class CodeSource implements Serializable {
 
-    private URL location;
-    private java.security.cert.Certificate [] certificates;
+    private final URL location;
+    private final java.security.cert.Certificate [] certificates;
 
-    public CodeSource(URL location, java.security.cert.Certificate[] certificates) {
+    public CodeSource(final URL location, final java.security.cert.Certificate[] certificates) {
 	this.location = location;
-	this.certificates = certificates;
+	if (certificates != null) {
+	    this.certificates = (java.security.cert.Certificate[]) certificates.clone();
+	} else {
+	    this.certificates = null;
+	}
     }
 
     public boolean equals(Object obj) {
@@ -42,12 +46,30 @@
 
 	CodeSource that = (CodeSource) obj;
 
-	return getLocation().equals(that.getLocation())
-	    && getCertSet().equals(that.getCertSet());
+	if (location == null) {
+	    if (that.location != null) {
+		return false;
+	    }
+	} else if (!location.equals(that.location)) {
+	    return false;
+	}
+	if (certificates == null) {
+	    if (that.certificates != null) {
+		return false;
+	    }
+	} else {
+	    if (!getCertSet().equals(that.getCertSet())) {
+		return false;
+	    }
+	}
+	return true;
     }
 
     public final java.security.cert.Certificate[] getCertificates() {
-	return certificates;
+	if (certificates == null) {
+	    return null;
+	}
+	return (java.security.cert.Certificate[]) certificates.clone();
     }
 
     private Set getCertSet() {
@@ -59,8 +81,16 @@
     }
 
     public int hashCode() {
-	return getLocation().hashCode()
-	    ^ getCertSet().hashCode();
+	int sum = 0;
+	if (location != null) {
+	    sum += location.hashCode();
+	}
+	if (certificates != null) {
+	    for (int i = 0; i < certificates.length; i++) {
+		sum += certificates[i].hashCode();
+	    }
+	}
+	return sum;
     }
 
     public boolean implies(CodeSource other) {
@@ -99,7 +129,7 @@
 	    }
 
 	    /* Check 3.4 */
-	    if  (getLocation().getHost() != null) {
+	    if	(getLocation().getHost() != null && ! getLocation().getHost().equals("")) {
 		if (! new SocketPermission(getLocation().getHost(), "")
 		    .implies(new SocketPermission(other.getLocation().getHost(), ""))) {
 		    return false;
@@ -151,7 +181,7 @@
     public String toString() {
 	return getClass().getName()
 	    + "[location=" + getLocation()
-	    + ",certificates=" + getCertSet()
+	    + ",certificates=" + (certificates != null ? getCertSet().toString() : "none")
 	    + ']';
     }
 }

--=-=-=--