You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by km...@apache.org on 2009/06/25 19:04:20 UTC

svn commit: r788436 - in /db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode: BCClass.java GClass.java

Author: kmarsden
Date: Thu Jun 25 17:04:19 2009
New Revision: 788436

URL: http://svn.apache.org/viewvc?rev=788436&view=rev
Log:
DERBY-4287 call to System.getProperty in BCClass.java is not wrapped in a priv block so may fail when running under SecurityManager

Also wraps call to FileOutputStream


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/BCClass.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/GClass.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/BCClass.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/BCClass.java?rev=788436&r1=788435&r2=788436&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/BCClass.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/BCClass.java Thu Jun 25 17:04:19 2009
@@ -40,6 +40,7 @@
 import org.apache.derby.iapi.services.classfile.VMOpcode;
 
 import java.lang.reflect.Modifier;
+import java.security.AccessController;
 
 import org.apache.derby.iapi.services.sanity.SanityManager;
 import org.apache.derby.iapi.services.classfile.VMDescriptor;
@@ -149,7 +150,15 @@
 		if (SanityManager.DEBUG) {
 			if (SanityManager.DEBUG_ON("DumpClassFile")) {
 				/* Dump the file in derby.system.home */
-				String systemHome = System.getProperty(Property.SYSTEM_HOME_PROPERTY,".");
+				String systemHome = (String )AccessController.doPrivileged
+				(new java.security.PrivilegedAction(){
+
+					public Object run(){
+						return System.getProperty(Property.SYSTEM_HOME_PROPERTY,".");
+
+					}
+				}
+				);				
 				writeClassFile(systemHome,false,null);
 			}
 		}

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/GClass.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/GClass.java?rev=788436&r1=788435&r2=788436&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/GClass.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/bytecode/GClass.java Thu Jun 25 17:04:19 2009
@@ -32,8 +32,12 @@
 import org.apache.derby.iapi.util.ByteArray;
 
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 
 /**
  * This is a common superclass for the various impls.
@@ -72,20 +76,30 @@
 
 		filename = filename + ".class";
 
-		File classFile = new File(dir,filename);
+		final File classFile = new File(dir,filename);
 
 		// find the error stream
 		HeaderPrintWriter errorStream = Monitor.getStream();
-
+		FileOutputStream fos = null;
 		try {
-			FileOutputStream fis = new FileOutputStream(classFile);
-			fis.write(bytecode.getArray(),
+			try {
+				fos =  (FileOutputStream)AccessController.doPrivileged(
+						new PrivilegedExceptionAction() {
+							public Object run()
+							throws FileNotFoundException {
+								return new FileOutputStream(classFile);
+							}
+						});
+			} catch (PrivilegedActionException pae) {
+				throw (FileNotFoundException)pae.getCause();
+			}
+			fos.write(bytecode.getArray(),
 				bytecode.getOffset(), bytecode.getLength());
-			fis.flush();
+			fos.flush();
 			if (logMessage) {
 				errorStream.printlnWithHeader("Wrote class "+getFullName()+" to file "+classFile.toString()+". Please provide support with the file and the following exception message: "+t);
 			}
-			fis.close();
+			fos.close();
 		} catch (IOException e) {
 			if (SanityManager.DEBUG)
 				SanityManager.THROWASSERT("Unable to write .class file", e);