db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r789148 - in /db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/services/bytecode: BCClass.java GClass.java
Date Sun, 28 Jun 2009 20:33:56 GMT
Author: kmarsden
Date: Sun Jun 28 20:33:56 2009
New Revision: 789148

URL: http://svn.apache.org/viewvc?rev=789148&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 wrapped FileOutputStream creation 


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

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/services/bytecode/BCClass.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/services/bytecode/BCClass.java?rev=789148&r1=789147&r2=789148&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/services/bytecode/BCClass.java
(original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/services/bytecode/BCClass.java
Sun Jun 28 20:33:56 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/branches/10.5/java/engine/org/apache/derby/impl/services/bytecode/GClass.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/services/bytecode/GClass.java?rev=789148&r1=789147&r2=789148&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/services/bytecode/GClass.java
(original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/impl/services/bytecode/GClass.java
Sun Jun 28 20:33:56 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);



Mime
View raw message