From ec49725d4695c22f5df4ce0d36fedf3d6ba6c4eb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 24 Jul 2024 14:14:07 +0000 Subject: [PATCH 1/5] Bump maven.surefire.version from 3.3.0 to 3.3.1 Bumps `maven.surefire.version` from 3.3.0 to 3.3.1. Updates `org.apache.maven.plugins:maven-surefire-plugin` from 3.3.0 to 3.3.1 - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.3.0...surefire-3.3.1) Updates `org.apache.maven.plugins:maven-surefire-report-plugin` from 3.3.0 to 3.3.1 - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.3.0...surefire-3.3.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.apache.maven.plugins:maven-surefire-report-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1d4d33ea..1bdf1449 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ b000 1.6.0 2.43.0 - 3.3.0 + 3.3.1 both ${maven.multiModuleProjectDirectory}/logging.properties From 4e80545fb78ef57e1fae773c26ce7de0cc5272ac Mon Sep 17 00:00:00 2001 From: Raffi Khatchadourian Date: Wed, 24 Jul 2024 15:09:55 -0400 Subject: [PATCH 2/5] Be a little more lenient on what constitutes a test case entrypoint. --- .../cast/python/ipa/callgraph/PytestEntrypointBuilder.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/ipa/callgraph/PytestEntrypointBuilder.java b/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/ipa/callgraph/PytestEntrypointBuilder.java index b490644b..5e169d56 100644 --- a/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/ipa/callgraph/PytestEntrypointBuilder.java +++ b/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/ipa/callgraph/PytestEntrypointBuilder.java @@ -90,7 +90,8 @@ public static boolean isPytestCase(IClass klass) { IClass container = dmb.getContainer(); String containerName = container.getReference().getName().getClassName().toString(); - if (containerName.startsWith("Test") && container instanceof PythonClass) { + if ((containerName.startsWith("Test") || containerName.endsWith("Test")) + && container instanceof PythonClass) { // It's a test class. PythonClass containerClass = (PythonClass) container; From 02366ecbcc90247d8c192f7a5db756b88f6eb9e9 Mon Sep 17 00:00:00 2001 From: Raffi Khatchadourian Date: Thu, 25 Jul 2024 12:39:39 -0400 Subject: [PATCH 3/5] Handle the wildcard import property read case. For example: `from X.Y.Z import *`. --- .../PythonSSAPropagationCallGraphBuilder.java | 180 +++++++++--------- 1 file changed, 95 insertions(+), 85 deletions(-) diff --git a/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/ipa/callgraph/PythonSSAPropagationCallGraphBuilder.java b/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/ipa/callgraph/PythonSSAPropagationCallGraphBuilder.java index c6e359cd..96ed805d 100644 --- a/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/ipa/callgraph/PythonSSAPropagationCallGraphBuilder.java +++ b/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/ipa/callgraph/PythonSSAPropagationCallGraphBuilder.java @@ -231,91 +231,7 @@ public void visitPropertyRead(AstPropertyRead instruction) { logger.fine( "Detected wildcard for " + instruction.getMemberRef() + " in " + instruction + "."); - int objRef = instruction.getObjectRef(); - logger.fine("Seeing if " + objRef + " refers to an import."); - - SSAInstruction def = this.du.getDef(objRef); - logger.finer("Found definition: " + def + "."); - - TypeName scriptTypeName = - this.ir.getMethod().getReference().getDeclaringClass().getName(); - logger.finer("Found script: " + scriptTypeName + "."); - - String scriptName = getScriptName(scriptTypeName); - logger.fine("Script name is: " + scriptName); - assert scriptName.endsWith("." + PYTHON_FILE_EXTENSION); - - if (def instanceof SSAInvokeInstruction) { - // Library case. - SSAInvokeInstruction invokeInstruction = (SSAInvokeInstruction) def; - MethodReference declaredTarget = invokeInstruction.getDeclaredTarget(); - Atom declaredTargetName = declaredTarget.getName(); - - if (declaredTargetName.equals(IMPORT_FUNCTION_NAME)) { - // It's an import "statement" importing a library. - logger.fine("Found library import statement in: " + scriptTypeName + "."); - - logger.info( - "Adding: " - + declaredTarget.getDeclaringClass().getName().toString().substring(1) - + " to wildcard imports for: " - + scriptName - + "."); - - // Add the library to the script's queue of wildcard imports. - getBuilder() - .getScriptToWildcardImports() - .compute( - scriptName, - (k, v) -> { - if (v == null) { - Deque deque = new ArrayDeque<>(); - deque.push(declaredTarget); - return deque; - } else { - v.push(declaredTarget); - return v; - } - }); - } - } else if (def instanceof SSAGetInstruction) { - // We are importing from a script. - SSAGetInstruction getInstruction = (SSAGetInstruction) def; - String strippedFieldName = getStrippedDeclaredFieldName(getInstruction); - - MethodReference methodReference = - getMethodReferenceRepresentingScript(strippedFieldName); - - logger.info( - "Adding: " - + methodReference.getDeclaringClass().getName().toString().substring(1) - + " to wildcard imports for: " - + scriptName - + "."); - - // Add the script to the queue of this script's wildcard imports. - getBuilder() - .getScriptToWildcardImports() - .compute( - scriptName, - (k, v) -> { - if (v == null) { - Deque deque = new ArrayDeque<>(); - deque.push(methodReference); - return deque; - } else { - v.push(methodReference); - return v; - } - }); - } else - throw new IllegalArgumentException( - "Not expecting the definition: " - + def - + " of the object reference of: " - + instruction - + " to be: " - + def.getClass()); + processWildcardImports(instruction); } // check if we are reading from an module initialization script. @@ -346,6 +262,100 @@ public void visitPropertyRead(AstPropertyRead instruction) { } } + /** + * Processes the given {@link AstPropertyRead} for any potential wildcard imports being utilized + * by the instruction. + * + * @param instruction The {@link AstPropertyRead} whose definition may depend on a wildcard + * import. + */ + private void processWildcardImports(AstPropertyRead instruction) { + int objRef = instruction.getObjectRef(); + logger.fine("Seeing if " + objRef + " refers to an import."); + + SSAInstruction def = this.du.getDef(objRef); + logger.finer("Found definition: " + def + "."); + + TypeName scriptTypeName = this.ir.getMethod().getReference().getDeclaringClass().getName(); + logger.finer("Found script: " + scriptTypeName + "."); + + String scriptName = getScriptName(scriptTypeName); + logger.fine("Script name is: " + scriptName); + assert scriptName.endsWith("." + PYTHON_FILE_EXTENSION); + + if (def instanceof SSAInvokeInstruction) { + // Library case. + SSAInvokeInstruction invokeInstruction = (SSAInvokeInstruction) def; + MethodReference declaredTarget = invokeInstruction.getDeclaredTarget(); + Atom declaredTargetName = declaredTarget.getName(); + + if (declaredTargetName.equals(IMPORT_FUNCTION_NAME)) { + // It's an import "statement" importing a library. + logger.fine("Found library import statement in: " + scriptTypeName + "."); + + logger.info( + "Adding: " + + declaredTarget.getDeclaringClass().getName().toString().substring(1) + + " to wildcard imports for: " + + scriptName + + "."); + + // Add the library to the script's queue of wildcard imports. + getBuilder() + .getScriptToWildcardImports() + .compute( + scriptName, + (k, v) -> { + if (v == null) { + Deque deque = new ArrayDeque<>(); + deque.push(declaredTarget); + return deque; + } else { + v.push(declaredTarget); + return v; + } + }); + } + } else if (def instanceof SSAGetInstruction) { + // We are importing from a script. + SSAGetInstruction getInstruction = (SSAGetInstruction) def; + String strippedFieldName = getStrippedDeclaredFieldName(getInstruction); + + MethodReference methodReference = getMethodReferenceRepresentingScript(strippedFieldName); + + logger.info( + "Adding: " + + methodReference.getDeclaringClass().getName().toString().substring(1) + + " to wildcard imports for: " + + scriptName + + "."); + + // Add the script to the queue of this script's wildcard imports. + getBuilder() + .getScriptToWildcardImports() + .compute( + scriptName, + (k, v) -> { + if (v == null) { + Deque deque = new ArrayDeque<>(); + deque.push(methodReference); + return deque; + } else { + v.push(methodReference); + return v; + } + }); + } else if (def instanceof AstPropertyRead) processWildcardImports((AstPropertyRead) def); + else + throw new IllegalArgumentException( + "Not expecting the definition: " + + def + + " of the object reference of: " + + instruction + + " to be: " + + def.getClass()); + } + /** * Given a script's name, returns the {@link MethodReference} representing the script. * From 5d72128cbe977fa6c2d226ad4449f1568bce9eba Mon Sep 17 00:00:00 2001 From: Raffi Khatchadourian Date: Thu, 25 Jul 2024 17:40:35 -0400 Subject: [PATCH 4/5] Issue a warning instead of throwing an exception. --- .../com/ibm/wala/cast/python/util/Util.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/util/Util.java b/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/util/Util.java index 5e5f9f5d..233fc038 100644 --- a/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/util/Util.java +++ b/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/util/Util.java @@ -168,29 +168,28 @@ private Util() {} /** * If the given {@link ConstantKey}'s value is null, then issue a warning and return - * null. Otherwise, throw an {@link IllegalArgumentException} stating that an {@link - * AllocationSiteInNode} cannot be extracted from the given {@link ConstantKey}. A value of + * null. Otherwise, issue a warning stating that an {@link AllocationSiteInNode} + * cannot be extracted from the given {@link ConstantKey}. A value of * null most likely indicates that a receiver can potentially be null. * * @param constantKey The {@link ConstantKey} from which to extract the corresponding {@link * AllocationSiteInNode}. - * @return null if the given {@link ConstantKey}'s value is null. - * @throws IllegalArgumentException If the constant's value is another else other than null - * . + * @return null. */ private static AllocationSiteInNode getAllocationSiteInNode(ConstantKey constantKey) { Object value = constantKey.getValue(); - if (value == null) { + if (value == null) LOGGER.warning("Can't extract AllocationSiteInNode from: " + constantKey + "."); - return null; - } else - throw new IllegalArgumentException( + else + LOGGER.warning( "Can't extract AllocationSiteInNode from: " + constantKey + ". Not expecting value of: " + value + " from ConstantKey."); + + return null; } /** From abc9b1677411c3738dc042f5e7f37b523197b9e0 Mon Sep 17 00:00:00 2001 From: Raffi Khatchadourian Date: Thu, 25 Jul 2024 17:46:43 -0400 Subject: [PATCH 5/5] Revert "Issue a warning instead of throwing an exception." This reverts commit 5d72128cbe977fa6c2d226ad4449f1568bce9eba. --- .../com/ibm/wala/cast/python/util/Util.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/util/Util.java b/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/util/Util.java index 233fc038..5e5f9f5d 100644 --- a/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/util/Util.java +++ b/com.ibm.wala.cast.python/source/com/ibm/wala/cast/python/util/Util.java @@ -168,28 +168,29 @@ private Util() {} /** * If the given {@link ConstantKey}'s value is null, then issue a warning and return - * null. Otherwise, issue a warning stating that an {@link AllocationSiteInNode} - * cannot be extracted from the given {@link ConstantKey}. A value of + * null. Otherwise, throw an {@link IllegalArgumentException} stating that an {@link + * AllocationSiteInNode} cannot be extracted from the given {@link ConstantKey}. A value of * null most likely indicates that a receiver can potentially be null. * * @param constantKey The {@link ConstantKey} from which to extract the corresponding {@link * AllocationSiteInNode}. - * @return null. + * @return null if the given {@link ConstantKey}'s value is null. + * @throws IllegalArgumentException If the constant's value is another else other than null + * . */ private static AllocationSiteInNode getAllocationSiteInNode(ConstantKey constantKey) { Object value = constantKey.getValue(); - if (value == null) + if (value == null) { LOGGER.warning("Can't extract AllocationSiteInNode from: " + constantKey + "."); - else - LOGGER.warning( + return null; + } else + throw new IllegalArgumentException( "Can't extract AllocationSiteInNode from: " + constantKey + ". Not expecting value of: " + value + " from ConstantKey."); - - return null; } /**