/hg/release/icedtea6-1.7: 5 new changesets

dbhole at icedtea.classpath.org dbhole at icedtea.classpath.org
Fri Jul 9 09:30:36 PDT 2010


changeset d133c2298825 in /hg/release/icedtea6-1.7
details: http://icedtea.classpath.org/hg/release/icedtea6-1.7?cmd=changeset;node=d133c2298825
author: Omair Majid <omajid at redhat.com>
date: Tue Jun 29 14:19:38 2010 -0400

	Netx: make path sanitization consistent; use a blacklisting
	approach.

	2010-06-29 Omair Majid <omajid at redhat.com>

	 * netx/net/sourceforge/jnlp/cache/CacheUtil.java
	(urlToPath): Call FileUtils.sanitizePath. (fixPath): Moved to...
	    * netx/net/sourceforge/jnlp/util/FileUtils.java (sanitizePath):
	New function. Moved from CacheUtil.java (sanitizeFileName): Use
	a blacklisting approach rather than a whitelisting approach:
	should work better with non ascii filenames.


changeset 4bbd10e42fd2 in /hg/release/icedtea6-1.7
details: http://icedtea.classpath.org/hg/release/icedtea6-1.7?cmd=changeset;node=4bbd10e42fd2
author: Omair Majid <omajid at redhat.com>
date: Tue Jun 29 14:26:57 2010 -0400

	Netx: make the SingleInstanceServer thread a daemon thread

	2010-06-29 Omair Majid <omajid at redhat.com>

	 * netx/net/sourceforge/jnlp/services/XSingleInstanceService.java
	(startListeningServer): Mark the thread as a daemon so the JVM can
	shutdown if there are no other non-daemon thread running.


changeset fa5d7ae7e7f2 in /hg/release/icedtea6-1.7
details: http://icedtea.classpath.org/hg/release/icedtea6-1.7?cmd=changeset;node=fa5d7ae7e7f2
author: Omair Majid <omajid at redhat.com>
date: Thu Jun 24 09:40:43 2010 -0400

	netx: handle JNLP files which use native libraries but do not
	indiate it

	2010-06-24 Omair Majid <omajid at redhat.com>

	 * netx/net/sourceforge/jnlp/SecurityDesc.java: Fix comments.
	    * netx/net/sourceforge/jnlp/JNLPClassLoader.java (activateJars):
	Always call activateNative. (activateNative): Search for native
	code anywhere in the jar.


changeset 8cc0ee1848d6 in /hg/release/icedtea6-1.7
details: http://icedtea.classpath.org/hg/release/icedtea6-1.7?cmd=changeset;node=8cc0ee1848d6
author: Omair Majid <omajid at redhat.com>
date: Tue Jun 29 15:48:10 2010 -0400

	Netx: allow jnlp classloaders to share native libraries 2010-06-29
	Omair Majid <omajid at redhat.com>

	 * netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java
	nativeDirectories: New variable. Contains a list of directories that
	contain native libraries. (getInstance): Tell other classloaders
	about the native directory. (getNativeDir): Add the new native
	directory to nativeDirectories. (addNativeDirectory): New
	function. (getNativeDirectories): New function.
	(findLibrary): Look in all the native directories for the native
	library.


changeset 670a8e9e498b in /hg/release/icedtea6-1.7
details: http://icedtea.classpath.org/hg/release/icedtea6-1.7?cmd=changeset;node=670a8e9e498b
author: Deepak Bhole <dbhole at redhat.com>
date: Fri Jul 09 12:30:10 2010 -0400

	From mwong at redhat.com:

	Added encoding support for netx.


diffstat:

7 files changed, 230 insertions(+), 68 deletions(-)
ChangeLog                                                    |   44 ++++
rt/net/sourceforge/jnlp/Parser.java                          |   73 +++++++
rt/net/sourceforge/jnlp/SecurityDesc.java                    |    9 
rt/net/sourceforge/jnlp/cache/CacheUtil.java                 |   17 -
rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java         |   93 +++++++---
rt/net/sourceforge/jnlp/services/XSingleInstanceService.java |   11 -
rt/net/sourceforge/jnlp/util/FileUtils.java                  |   51 +++--

diffs (477 lines):

diff -r a8aeb44946cb -r 670a8e9e498b ChangeLog
--- a/ChangeLog	Fri Jul 09 10:59:53 2010 -0400
+++ b/ChangeLog	Fri Jul 09 12:30:10 2010 -0400
@@ -1,3 +1,47 @@ 2010-07-09  Deepak Bhole <dbhole at redhat.
+2010-07-08  Man Lung Wong  <mwong at redhat.com>
+
+    * netx/net/sourceforge/jnlp/Parser.java:
+    (getRootNode): Used BufferedInputStream instead of InputStream to
+	have mark and reset method available. Passed the encoding to the
+	constructor of InputStreamReader, such that the stream will now
+	be parsed with the encoding the jnlp file is in.
+    (getEncoding): A new method which checks the first four bytes of input
+	and determines what the files encoding is.
+
+2010-06-29  Omair Majid <omajid at redhat.com>
+
+	* netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java
+	nativeDirectories: New variable. Contains a list of directories that
+	contain native libraries.
+	(getInstance): Tell other classloaders about the native directory.
+	(getNativeDir): Add the new native directory to nativeDirectories.
+	(addNativeDirectory): New function.
+	(getNativeDirectories): New function.
+	(findLibrary): Look in all the native directories for the native library.
+
+2010-06-24 Omair Majid <omajid at redhat.com>
+
+	* netx/net/sourceforge/jnlp/SecurityDesc.java: Fix comments.
+	* netx/net/sourceforge/jnlp/JNLPClassLoader.java
+	(activateJars): Always call activateNative.
+	(activateNative): Search for native code anywhere in the jar.
+
+2010-06-29  Omair Majid <omajid at redhat.com>
+
+	* netx/net/sourceforge/jnlp/services/XSingleInstanceService.java
+	(startListeningServer): Mark the thread as a daemon so the JVM can
+	shutdown if there are no other non-daemon thread running.
+
+2010-06-29 Omair Majid <omajid at redhat.com>
+
+	* netx/net/sourceforge/jnlp/cache/CacheUtil.java
+	(urlToPath): Call FileUtils.sanitizePath.
+	(fixPath): Moved to...
+	* netx/net/sourceforge/jnlp/util/FileUtils.java
+	(sanitizePath): New function. Moved from CacheUtil.java
+	(sanitizeFileName): Use a blacklisting approach rather than a whitelisting
+	approach: should work better with non ascii filenames.
+
 2010-07-09  Deepak Bhole <dbhole at redhat.com>
 
 	* plugin/icedteanp/IcedTeaJavaRequestProcessor.cc: Updated copyright date.
diff -r a8aeb44946cb -r 670a8e9e498b rt/net/sourceforge/jnlp/Parser.java
--- a/rt/net/sourceforge/jnlp/Parser.java	Fri Jul 09 10:59:53 2010 -0400
+++ b/rt/net/sourceforge/jnlp/Parser.java	Fri Jul 09 12:30:10 2010 -0400
@@ -1171,13 +1171,16 @@ class Parser {
             Node document = new Node(TinyParser.parseXML(input));
             Node jnlpNode = getChildNode(document, "jnlp"); // skip comments
             */
+            
+            //A BufferedInputStream is used to allow marking and reseting 
+            //of a stream.    
+            BufferedInputStream bs = new BufferedInputStream(input);
 
             /* NANO */
             final XMLElement xml = new XMLElement();
             final PipedInputStream pin = new PipedInputStream();
-            final PipedOutputStream pout = new PipedOutputStream(pin);
-            final InputStreamReader isr = new InputStreamReader(input);
-            
+            final PipedOutputStream pout = new PipedOutputStream(pin);   
+            final InputStreamReader isr = new InputStreamReader(bs, getEncoding(bs));    
             // Clean the jnlp xml file of all comments before passing
             // it to the parser.
             new Thread(
@@ -1200,7 +1203,69 @@ class Parser {
             throw new ParseException(R("PBadXML"), ex);
         }
     }
+    
+    /**
+     * Returns the name of the encoding used in this InputStream.
+     *
+     * @param input the InputStream
+     * @return a String representation of encoding
+     */
+    private static String getEncoding(InputStream input) throws IOException{
+        //Fixme: This only recognizes UTF-8, UTF-16, and 
+        //UTF-32, which is enough to parse the prolog portion of xml to
+        //find out the exact encoding (if it exists). The reason being
+        //there could be other encodings, such as ISO 8859 which is 8-bits
+        //but it supports latin characters.  
+        //So what needs to be done is to parse the prolog and retrieve
+        //the exact encoding from it.
 
+        int[] s = new int[4];
+        String encoding = "UTF-8";
+
+        //Determine what the first four bytes are and store 
+        //them into an int array.
+        input.mark(4);
+        for (int i = 0; i < 4; i++) {
+            s[i] = input.read(); 
+        }
+        input.reset();
+
+        //Set the encoding base on what the first four bytes of the
+        //inputstream turn out to be (following the information from
+        //www.w3.org/TR/REC-xml/#sec-guessing).
+        if (s[0] == 255) {
+            if (s[1] == 254) {
+                if (s[2] != 0 || s[3] != 0) {
+                    encoding = "UnicodeLittle";
+                } else {
+                    encoding = "X-UTF-32LE-BOM";
+                }
+            }
+        } else if (s[0] == 254 && s[1] == 255 && (s[2] != 0 || 
+          s[3] != 0)) {
+            encoding = "UTF-16";
+
+        } else if (s[0] == 0 && s[1] == 0 && s[2] == 254 && 
+          s[3] == 255) {
+            encoding = "X-UTF-32BE-BOM";
+
+        } else if (s[0] == 0 && s[1] == 0 && s[2] == 0 && 
+          s[3] == 60) {
+            encoding = "UTF-32BE";
+ 
+        } else if (s[0] == 60 && s[1] == 0 && s[2] == 0 && 
+          s[3] == 0) {
+            encoding = "UTF-32LE";
+
+        } else if (s[0] == 0 && s[1] == 60 && s[2] == 0 && 
+          s[3] == 63) { 
+            encoding = "UTF-16BE"; 
+        } else if (s[0] == 60 && s[1] == 0 && s[2] == 63 &&
+          s[3] == 0) { 
+            encoding = "UTF-16LE";
+        }
+
+        return encoding;
+    }
 }
 
-
diff -r a8aeb44946cb -r 670a8e9e498b rt/net/sourceforge/jnlp/SecurityDesc.java
--- a/rt/net/sourceforge/jnlp/SecurityDesc.java	Fri Jul 09 10:59:53 2010 -0400
+++ b/rt/net/sourceforge/jnlp/SecurityDesc.java	Fri Jul 09 12:30:10 2010 -0400
@@ -31,12 +31,9 @@ import java.awt.AWTPermission;
  */
 public class SecurityDesc {
 
-    // todo: make sure classloader's native code support checks
-    // the security permissions
-
-    // shouldn't need to verify that native code only runs in
-    // trusted environment because the parser and/or classloader
-    // should kick it.
+    /*
+     * We do not verify security here, the classloader deals with security
+     */
 
     /** All permissions. */
     public static final Object ALL_PERMISSIONS = "All";
diff -r a8aeb44946cb -r 670a8e9e498b rt/net/sourceforge/jnlp/cache/CacheUtil.java
--- a/rt/net/sourceforge/jnlp/cache/CacheUtil.java	Fri Jul 09 10:59:53 2010 -0400
+++ b/rt/net/sourceforge/jnlp/cache/CacheUtil.java	Fri Jul 09 12:30:10 2010 -0400
@@ -26,6 +26,7 @@ import javax.jnlp.*;
 
 import net.sourceforge.jnlp.*;
 import net.sourceforge.jnlp.runtime.*;
+import net.sourceforge.jnlp.util.FileUtils;
 
 /**
  * Provides static methods to interact with the cache, download
@@ -300,23 +301,9 @@ public class CacheUtil {
         path.append(File.separatorChar);
         path.append(location.getPath().replace('/', File.separatorChar));
 
-        return new File(JNLPRuntime.getBaseDir(), fixPath(path.toString()));
+        return new File(JNLPRuntime.getBaseDir(), FileUtils.sanitizePath(path.toString()));
     }
 
-    /**
-     * Clean up a string by removing characters that can't appear in
-     * a local file name.
-     */
-    private static String fixPath(String path) {
-        char badChars[] = { '\\', '/', ':', '*', '?', '"', '<', '>', '|' };
-
-        for (int i=0; i < badChars.length; i++)
-            if (badChars[i] != File.separatorChar)
-                if (-1 != path.indexOf(badChars[i]))
-                    path = path.replace(badChars[i], 'X');
-
-        return path;
-    }
 
     /**
      * Waits until the resources are downloaded, while showing a
diff -r a8aeb44946cb -r 670a8e9e498b rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java
--- a/rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java	Fri Jul 09 10:59:53 2010 -0400
+++ b/rt/net/sourceforge/jnlp/runtime/JNLPClassLoader.java	Fri Jul 09 12:30:10 2010 -0400
@@ -32,6 +32,7 @@ import java.security.Permissions;
 import java.security.Permissions;
 import java.security.PrivilegedAction;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.LinkedList;
@@ -80,11 +81,11 @@ public class JNLPClassLoader extends URL
     /** map from JNLPFile url to shared classloader */
     private static Map urlToLoader = new HashMap(); // never garbage collected!
 
-    /** number of times a classloader with native code is created */
-    private static int nativeCounter = 0;
-
     /** the directory for native code */
     private File nativeDir = null; // if set, some native code exists
+
+    /** a list of directories that contain native libraries */
+    private List<File> nativeDirectories = Collections.synchronizedList(new LinkedList<File>());
 
     /** security context */
     private AccessControlContext acc = AccessController.getContext();
@@ -229,18 +230,22 @@ public class JNLPClassLoader extends URL
 		        // loader for this unique key. Check.
 		        JNLPClassLoader extLoader = (JNLPClassLoader) urlToLoader.get(uniqueKey);
 
-		        if (extLoader != null) {
+		        if (extLoader != null && extLoader != loader) {
 		            for (URL u : loader.getURLs())
 		                extLoader.addURL(u);
+		            for (File nativeDirectory: loader.getNativeDirectories())
+		                extLoader.addNativeDirectory(nativeDirectory);
 
 		            loader = extLoader;
 		        }
 
                 // loader is now current + ext. But we also need to think of 
                 // the baseLoader
-		        if (baseLoader != null) {
+		        if (baseLoader != null && baseLoader != loader) {
                     for (URL u : loader.getURLs())
                         baseLoader.addURL(u);
+                    for (File nativeDirectory: loader.getNativeDirectories())
+                        baseLoader.addNativeDirectory(nativeDirectory);
 
                     loader = baseLoader;
                 } 
@@ -631,8 +636,8 @@ public class JNLPClassLoader extends URL
                             ex.printStackTrace();
                     }
 
-                    if (jar.isNative())
-                        activateNative(jar);
+                    // some programs place a native library in any jar
+                    activateNative(jar);
                 }
 
                 return null;
@@ -643,9 +648,9 @@ public class JNLPClassLoader extends URL
     }
 
     /**
-     * Enable the native code contained in a JAR by copying the
-     * native files into the filesystem.  Called in the security
-     * context of the classloader.
+     * Search for and enable any native code contained in a JAR by copying the
+     * native files into the filesystem. Called in the security context of the
+     * classloader.
      */
     protected void activateNative(JARDesc jar) {
         if (JNLPRuntime.isDebug())
@@ -658,17 +663,33 @@ public class JNLPClassLoader extends URL
         if (nativeDir == null)
             nativeDir = getNativeDir();
 
+        String[] librarySuffixes = { ".so", ".dylib", ".jnilib", ".framework", ".dll" };
+
         try {
             JarFile jarFile = new JarFile(localFile, false);
-            Enumeration entries = jarFile.entries();
+            Enumeration<JarEntry> entries = jarFile.entries();
 
             while (entries.hasMoreElements()) {
-                JarEntry e = (JarEntry) entries.nextElement();
+                JarEntry e = entries.nextElement();
 
-                if (e.isDirectory() || e.getName().indexOf('/') != -1)
+                if (e.isDirectory()) {
                     continue;
+                }
 
-                File outFile = new File(nativeDir, e.getName());
+                String name = new File(e.getName()).getName();
+                boolean isLibrary = false;
+
+                for (String suffix: librarySuffixes) {
+                    if (name.endsWith(suffix)) {
+                       isLibrary = true;
+                       break;
+                    }
+                }
+                if (!isLibrary) {
+                    continue;
+                }
+
+                File outFile = new File(nativeDir, name);
 
                 CacheUtil.streamCopy(jarFile.getInputStream(e),
                                      new FileOutputStream(outFile));
@@ -692,29 +713,47 @@ public class JNLPClassLoader extends URL
 
         if (!nativeDir.mkdirs()) 
             return null;
-        else
+        else {
+            // add this new native directory to the search path
+            addNativeDirectory(nativeDir);
             return nativeDir;
+        }
+    }
+
+    /**
+     * Adds the {@link File} to the search path of this {@link JNLPClassLoader}
+     * when trying to find a native library
+     */
+    protected void addNativeDirectory(File nativeDirectory) {
+        nativeDirectories.add(nativeDirectory);
+    }
+
+    /**
+     * Returns a list of all directories in the search path of the current classloader
+     * when it tires to find a native library.
+     * @return a list of directories in the search path for native libraries
+     */
+    protected List<File> getNativeDirectories() {
+        return nativeDirectories;
     }
 
     /**
      * Return the absolute path to the native library.
      */
     protected String findLibrary(String lib) {
-        if (nativeDir == null)
-            return null;
-
         String syslib = System.mapLibraryName(lib);
 
-        File target = new File(nativeDir, syslib);
-        if (target.exists())
-            return target.toString();
-        else {
-            String result = super.findLibrary(lib);
-            if (result != null)
-                return result;
+        for (File dir: getNativeDirectories()) {
+            File target = new File(dir, syslib);
+            if (target.exists())
+                return target.toString();
+        }
 
-            return findLibraryExt(lib);
-        }
+        String result = super.findLibrary(lib);
+        if (result != null)
+            return result;
+
+        return findLibraryExt(lib);
     }
 
     /**
diff -r a8aeb44946cb -r 670a8e9e498b rt/net/sourceforge/jnlp/services/XSingleInstanceService.java
--- a/rt/net/sourceforge/jnlp/services/XSingleInstanceService.java	Fri Jul 09 10:59:53 2010 -0400
+++ b/rt/net/sourceforge/jnlp/services/XSingleInstanceService.java	Fri Jul 09 12:30:10 2010 -0400
@@ -145,14 +145,21 @@ public class XSingleInstanceService impl
     }
 
     /**
-     * Start the listening server to accept arguments from new isntances of
+     * Start the listening server to accept arguments from new instances of
      * applications
      * 
      * @param lockFile
+     *            the {@link SingleInstanceLock} that the server should use
      */
     private void startListeningServer(SingleInstanceLock lockFile) {
         SingleInstanceServer server = new SingleInstanceServer(lockFile);
-        new Thread(server).start();
+        Thread serverThread = new Thread(server);
+        /* 
+         * mark as daemon so the JVM can shutdown if the server is the only
+         * thread running
+         */
+        serverThread.setDaemon(true);
+        serverThread.start();
     }
 
     /**
diff -r a8aeb44946cb -r 670a8e9e498b rt/net/sourceforge/jnlp/util/FileUtils.java
--- a/rt/net/sourceforge/jnlp/util/FileUtils.java	Fri Jul 09 10:59:53 2010 -0400
+++ b/rt/net/sourceforge/jnlp/util/FileUtils.java	Fri Jul 09 12:30:10 2010 -0400
@@ -14,35 +14,58 @@
 // License along with this library; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
-
 package net.sourceforge.jnlp.util;
 
+import java.io.File;
+
 /**
- * This class contains a few file-related utility functions. 
+ * This class contains a few file-related utility functions.
  * 
  * @author Omair Majid
  */
 
-public class FileUtils {
+public final class FileUtils {
 
-    
+    /**
+     * list of characters not allowed in filenames
+     */
+    private static final char INVALID_CHARS[] = { '\\', '/', ':', '*', '?', '"', '<', '>', '|' };
+
+    private static final char SANITIZED_CHAR = '_';
+
+    /**
+     * Clean up a string by removing characters that can't appear in a local
+     * file name.
+     *
+     * @param path
+     *        the path to sanitize
+     * @return a sanitized version of the input which is suitable for using as a
+     *         file path
+     */
+    public static String sanitizePath(String path) {
+
+        for (int i = 0; i < INVALID_CHARS.length; i++)
+            if (INVALID_CHARS[i] != File.separatorChar)
+                if (-1 != path.indexOf(INVALID_CHARS[i]))
+                    path = path.replace(INVALID_CHARS[i], SANITIZED_CHAR);
+
+        return path;
+    }
+
     /**
      * Given an input, return a sanitized form of the input suitable for use as
      * a file/directory name
-     * 
+     *
      * @param input
      * @return a sanitized version of the input
      */
-    public static String sanitizeFileName(String input) {
+    public static String sanitizeFileName(String filename) {
 
-        /*
-         * FIXME
-         * 
-         * Assuming safe characters are 'a-z','A-Z','0-9', '_', '.'
-         */
+        for (int i = 0; i < INVALID_CHARS.length; i++)
+            if (-1 != filename.indexOf(INVALID_CHARS[i]))
+                filename = filename.replace(INVALID_CHARS[i], SANITIZED_CHAR);
 
-        String sanitizedName = input.replaceAll("[^a-zA-Z0-9.]", "_");
-        return sanitizedName;
+        return filename;
     }
-    
+
 }



More information about the distro-pkg-dev mailing list