db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1609099 - in /db/derby/code/trunk/java: engine/org/apache/derby/catalog/ engine/org/apache/derby/loc/ shared/org/apache/derby/shared/common/reference/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Wed, 09 Jul 2014 11:07:19 GMT
Author: kahatlen
Date: Wed Jul  9 11:07:19 2014
New Revision: 1609099

URL: http://svn.apache.org/r1609099
Log:
DERBY-6626: Check type of user-supplied modules before creating instances

Check explicitly that a custom tool implements the OptionalTool interface.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/catalog/Java5SystemProcedures.java
    db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
    db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/OptionalToolsTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/catalog/Java5SystemProcedures.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/catalog/Java5SystemProcedures.java?rev=1609099&r1=1609098&r2=1609099&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/catalog/Java5SystemProcedures.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/catalog/Java5SystemProcedures.java Wed
Jul  9 11:07:19 2014
@@ -23,7 +23,6 @@ package org.apache.derby.catalog;
 
 import java.sql.SQLException;
 
-import org.apache.derby.iapi.sql.conn.ConnectionUtil;
 import org.apache.derby.iapi.sql.dictionary.OptionalTool;
 import org.apache.derby.iapi.error.PublicAPI;
 import org.apache.derby.iapi.error.StandardException;
@@ -31,7 +30,6 @@ import org.apache.derby.iapi.reference.S
 import org.apache.derby.iapi.services.context.ContextService;
 import org.apache.derby.iapi.services.loader.ClassFactory;
 import org.apache.derby.iapi.services.loader.ClassFactoryContext;
-import org.apache.derby.shared.common.sanity.SanityManager;
 
 /**
  * <p>
@@ -101,10 +99,19 @@ public  class   Java5SystemProcedures
             String              toolClassName = findToolClassName( toolName, optionalArgs
);            
             OptionalTool    tool = null;
 
+            Class<?> toolClass;
             try {
-                tool = (OptionalTool) classFactory.loadApplicationClass( toolClassName ).newInstance();
+                toolClass = classFactory.loadApplicationClass( toolClassName );
             }
             catch (ClassNotFoundException cnfe) { throw wrap( cnfe ); }
+
+            if (!OptionalTool.class.isAssignableFrom(toolClass)) {
+                throw badCustomTool(toolClassName);
+            }
+
+            try {
+                tool = (OptionalTool) toolClass.newInstance();
+            }
             catch (InstantiationException ie) { throw wrap( ie ); }
             catch (IllegalAccessException iae) { throw wrap( iae ); }
 
@@ -147,6 +154,11 @@ public  class   Java5SystemProcedures
         return StandardException.newException( SQLState.LANG_UNKNOWN_TOOL_NAME,  toolName
);
     }
 
+    private static StandardException badCustomTool(String className) {
+        return StandardException.newException(
+                SQLState.LANG_UNKNOWN_CUSTOM_TOOL_NAME, className);
+    }
+
     /**
      * <p>
      * For a custom tool, we strip the first arg from the list of optional args. By

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=1609099&r1=1609098&r2=1609099&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 Wed Jul  9 11:07:19
2014
@@ -3860,6 +3860,12 @@ Guide.
             </msg>
 
             <msg>
+                <name>X0Y88.S.1</name>
+                <text>The class '{0}' does not implement the org.apache.derby.iapi.sql.dictionary.OptionalTool
interface.</text>
+                <arg>className</arg>
+            </msg>
+
+            <msg>
                 <name>X0Y89.S</name>
                 <text>Bad arguments passed to SYSCS_UTIL.SYSCS_REGISTER_TOOL(). Please
consult the Reference Manual section which describes this system procedure.</text>
             </msg>

Modified: db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java?rev=1609099&r1=1609098&r2=1609099&view=diff
==============================================================================
--- db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
(original)
+++ db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
Wed Jul  9 11:07:19 2014
@@ -1433,6 +1433,7 @@ public interface SQLState {
 	String LANG_CANT_FLUSH_PREALLOCATOR                                = "X0Y86.S";
 	String LANG_BAD_UDA_OR_FUNCTION_NAME                                = "X0Y87.S";
 	String LANG_UNKNOWN_TOOL_NAME                                = "X0Y88.S";
+    String LANG_UNKNOWN_CUSTOM_TOOL_NAME                              = "X0Y88.S.1";
 	String LANG_BAD_OPTIONAL_TOOL_ARGS                                = "X0Y89.S";
 	String LANG_CANT_INSTANTIATE_CLASS                                = "X0Y90.S";
     String LANG_SET_CONSTRAINT_NOT_DEFERRABLE                         = "X0Y91.S";

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/OptionalToolsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/OptionalToolsTest.java?rev=1609099&r1=1609098&r2=1609099&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/OptionalToolsTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/OptionalToolsTest.java
Wed Jul  9 11:07:19 2014
@@ -425,7 +425,7 @@ public class OptionalToolsTest  extends 
         expectExecutionError
             (
              dboConnection,
-             UNEXPECTED_USER_EXCEPTION,
+             UNKNOWN_TOOL,
              "call syscs_util.syscs_register_tool( 'customTool', true, 'java.lang.String'
)"
              );
 



Mime
View raw message