db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1629192 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ engine/org/apache/derby/loc/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/tests/lang/ testing/org/apac...
Date Fri, 03 Oct 2014 12:36:07 GMT
Author: rhillegas
Date: Fri Oct  3 12:36:06 2014
New Revision: 1629192

URL: http://svn.apache.org/r1629192
Log:
DERBY-6635: Prevent the optimizerTracing optional tool from writing its output over an existing
file; commit derby-6635-01-ab-noOverwrite.diff.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/OptimizerTracer.java
    db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/importExportIJ.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MergeStatementTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XMLOptimizerTraceTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SupportFilesSetup.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/OptimizerTracer.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/OptimizerTracer.java?rev=1629192&r1=1629191&r2=1629192&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/OptimizerTracer.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/OptimizerTracer.java
Fri Oct  3 12:36:06 2014
@@ -21,12 +21,16 @@
 
 package org.apache.derby.impl.sql.compile;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
+import java.security.PrivilegedExceptionAction;
 import java.sql.SQLException;
 import org.apache.derby.iapi.db.OptimizerTrace;
+import org.apache.derby.iapi.error.PublicAPI;
+import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.reference.SQLState;
 import org.apache.derby.iapi.services.context.Context;
 import org.apache.derby.iapi.services.context.ContextService;
@@ -152,12 +156,23 @@ public	class   OptimizerTracer  implemen
             {
                 pw = AccessController.doPrivileged
                     (
-                     new PrivilegedAction<PrintWriter>()
+                     new PrivilegedExceptionAction<PrintWriter>()
                      {
-                         public PrintWriter run()
+                         public PrintWriter run() throws SQLException
                          {
                              try {
-                                 return new PrintWriter( configurationParameters[ 0 ] );
+                                 String fileName = configurationParameters[ 0 ];
+                                 File   outputFile = new File( fileName );
+
+                                 if ( outputFile.exists() )
+                                 {
+                                     throw PublicAPI.wrapStandardException
+                                         (
+                                          StandardException.newException( SQLState.DATA_FILE_EXISTS,
fileName )
+                                          );
+                                 }
+                                 
+                                 return new PrintWriter( outputFile );
                              } catch (IOException ioe) { throw new IllegalArgumentException(
ioe.getMessage(), ioe ); }
                          }  
                      }
@@ -175,7 +190,17 @@ public	class   OptimizerTracer  implemen
             if ( needsClosing ) { pw.close(); }
             
         }
-        catch (Exception e) { throw wrap( e ); }
+        catch (Exception e)
+        {
+            if ( e.getMessage() == null )
+            {
+                Throwable   cause = e.getCause();
+                if ( (cause != null) && (cause instanceof SQLException) )
+                { throw (SQLException) cause; }
+            }
+            
+            throw wrap( e );
+        }
         finally
         {
             OptimizerTrace.setOptimizerTracer( null );

Modified: db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml?rev=1629192&r1=1629191&r2=1629192&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml Fri Oct  3 12:36:06
2014
@@ -4763,7 +4763,7 @@ ln=lower-case two-letter ISO-639 languag
 
 	    <msg>
                 <name>XIE0S.S</name>
-		<text>The export operation was not performed, because the specified output file ({0})
already exists. Export processing will not overwrite an existing file, even if the process
has permissions to write to that file, due to security concerns, and to avoid accidental file
damage. Please either change the output file name in the export procedure arguments to specify
a file which does not exist, or delete the existing file, then retry the export operation.</text>
+		<text>The operation was not performed, because the specified output file ({0}) already
exists. The procedure will not overwrite an existing file, even if the process has permissions
to write to that file, due to security concerns, and to avoid accidental file damage. Please
either change the output file name in the procedure arguments to specify a file which does
not exist, or delete the existing file, then retry the operation.</text>
                 <arg>fileName</arg>
             </msg>
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/importExportIJ.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/importExportIJ.out?rev=1629192&r1=1629191&r2=1629192&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/importExportIJ.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/importExportIJ.out
Fri Oct  3 12:36:06 2014
@@ -805,7 +805,7 @@ ij> --
 --
 CALL SYSCS_UTIL.SYSCS_EXPORT_TABLE
 ( null, 'DERBY_2925_TAB', 'extout/derby-2925.txt', null, null, null);
-ERROR XIE0S: The export operation was not performed, because the specified output file (extout/derby-2925.txt)
already exists. Export processing will not overwrite an existing file, even if the process
has permissions to write to that file, due to security concerns, and to avoid accidental file
damage. Please either change the output file name in the export procedure arguments to specify
a file which does not exist, or delete the existing file, then retry the export operation.
+ERROR XIE0S: The operation was not performed, because the specified output file (extout/derby-2925.txt)
already exists. The procedure will not overwrite an existing file, even if the process has
permissions to write to that file, due to security concerns, and to avoid accidental file
damage. Please either change the output file name in the procedure arguments to specify a
file which does not exist, or delete the existing file, then retry the operation.
 ij> --
 -- Testing SYSCS_UTIL.SYSCS_EXPORT_QUERY
 --
@@ -820,7 +820,7 @@ ij> --
 --
 CALL SYSCS_UTIL.SYSCS_EXPORT_QUERY
 ('select * from DERBY_2925_TAB', 'extout/derby-2925-query.dat', null , null , null ) ;
-ERROR XIE0S: The export operation was not performed, because the specified output file (extout/derby-2925-query.dat)
already exists. Export processing will not overwrite an existing file, even if the process
has permissions to write to that file, due to security concerns, and to avoid accidental file
damage. Please either change the output file name in the export procedure arguments to specify
a file which does not exist, or delete the existing file, then retry the export operation.
+ERROR XIE0S: The operation was not performed, because the specified output file (extout/derby-2925-query.dat)
already exists. The procedure will not overwrite an existing file, even if the process has
permissions to write to that file, due to security concerns, and to avoid accidental file
damage. Please either change the output file name in the procedure arguments to specify a
file which does not exist, or delete the existing file, then retry the operation.
 ij> --
 -- Testing SYSCS_UTIL.SYSCS_EXPORT_QUERY_LOBS_TO_EXTFILE
 --
@@ -848,7 +848,7 @@ ij> --
 --
 CALL SYSCS_UTIL.SYSCS_EXPORT_QUERY_LOBS_TO_EXTFILE
 ('SELECT * FROM DERBY_2925_LOB','extout/derby-2925_data.dat', '\' ,'|','UTF-16','extout/derby-2925_lobs.dat');
-ERROR XIE0S: The export operation was not performed, because the specified output file (extout/derby-2925_data.dat)
already exists. Export processing will not overwrite an existing file, even if the process
has permissions to write to that file, due to security concerns, and to avoid accidental file
damage. Please either change the output file name in the export procedure arguments to specify
a file which does not exist, or delete the existing file, then retry the export operation.
+ERROR XIE0S: The operation was not performed, because the specified output file (extout/derby-2925_data.dat)
already exists. The procedure will not overwrite an existing file, even if the process has
permissions to write to that file, due to security concerns, and to avoid accidental file
damage. Please either change the output file name in the procedure arguments to specify a
file which does not exist, or delete the existing file, then retry the operation.
 ij> --
 -- Testing SYSCS_UTIL.SYSCS_EXPORT_QUERY_LOBS_TO_EXTFILE
 -- where lob file exists.

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MergeStatementTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MergeStatementTest.java?rev=1629192&r1=1629191&r2=1629192&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MergeStatementTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MergeStatementTest.java
Fri Oct  3 12:36:06 2014
@@ -9316,6 +9316,7 @@ public class MergeStatementTest extends 
     {
         Connection  dboConnection = openUserConnection( TEST_DBO );
         File    traceFile = SupportFilesSetup.getReadWrite( TRACE_FILE_NAME );
+        SupportFilesSetup.deleteFile( traceFile );
 
         //
         // Schema

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XMLOptimizerTraceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XMLOptimizerTraceTest.java?rev=1629192&r1=1629191&r2=1629192&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XMLOptimizerTraceTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XMLOptimizerTraceTest.java
Fri Oct  3 12:36:06 2014
@@ -46,6 +46,7 @@ public class XMLOptimizerTraceTest  exte
 
     private static  final   String  TRACE_FILE_NAME = "xott.xml";
     private static  final   String  SAVED_TRACE_NAME = "xmlOptimizer.trace";
+    private static  final   String  FILE_EXISTS = "XIE0S";
 
     ///////////////////////////////////////////////////////////////////////////////////
     //
@@ -228,6 +229,8 @@ public class XMLOptimizerTraceTest  exte
         Connection conn = getConnection();
         File    traceFile = SupportFilesSetup.getReadWrite( TRACE_FILE_NAME );
 
+        SupportFilesSetup.deleteFile( traceFile );
+
         // turn on xml-based optimizer tracing and run some queries
         goodStatement
             (
@@ -318,6 +321,25 @@ public class XMLOptimizerTraceTest  exte
 
         // use planCost to examine an outer join
         vetOuterJoin( conn );
+
+        // verify that you can't overwrite an existing file with xml output (DERBY-6635)
+        goodStatement
+            (
+             conn,
+             "call syscs_util.syscs_register_tool( 'optimizerTracing', true, 'xml' )"
+             );
+        expectExecutionError
+            (
+             conn,
+             FILE_EXISTS,
+             "call syscs_util.syscs_register_tool( 'optimizerTracing', false, '" + traceFile.getPath()
+ "' )"
+              );
+        goodStatement
+            (
+             conn,
+             "call syscs_util.syscs_register_tool( 'optimizerTracing', false )"
+             );
+
     }
 
     /**
@@ -576,6 +598,7 @@ public class XMLOptimizerTraceTest  exte
     private void vetOuterJoin( Connection conn ) throws Exception
     {
         File    traceFile = SupportFilesSetup.getReadWrite( TRACE_FILE_NAME );
+        SupportFilesSetup.deleteFile( traceFile );
 
         // turn on xml-based optimizer tracing
         goodStatement

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SupportFilesSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SupportFilesSetup.java?rev=1629192&r1=1629191&r2=1629192&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SupportFilesSetup.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/SupportFilesSetup.java
Fri Oct  3 12:36:06 2014
@@ -298,9 +298,13 @@ public class SupportFilesSetup extends T
 
     public static void deleteFile(final String fileName) 
     {
-        File f = new File(fileName);
-        if (PrivilegedFileOpsForTests.exists(f)) {
-            assertTrue(PrivilegedFileOpsForTests.delete(f));
+        deleteFile( new File(fileName) );
+    }
+
+    public static void deleteFile(final File file ) 
+    {
+        if (PrivilegedFileOpsForTests.exists(file)) {
+            assertTrue(PrivilegedFileOpsForTests.delete(file));
         }
     }
 }



Mime
View raw message