This repository has been archived by the owner on Nov 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
CCE when using a GString with a dynamic method pointer #93
Closed
Comments
I assume the workaround should have been. At least this works for me:
|
I reproduced this. A patch like the following against jenkinsci/workflow-cps-plugin#612 seems to fix the issue: diff --git a/lib/src/main/java/com/cloudbees/groovy/cps/impl/MethodPointerBlock.java b/lib/src/main/java/com/cloudbees/groovy/cps/impl/MethodPointerBlock.java
index 0aabad62..de033e1c 100644
--- a/lib/src/main/java/com/cloudbees/groovy/cps/impl/MethodPointerBlock.java
+++ b/lib/src/main/java/com/cloudbees/groovy/cps/impl/MethodPointerBlock.java
@@ -7,6 +7,7 @@ import com.cloudbees.groovy.cps.Next;
import com.cloudbees.groovy.cps.sandbox.CallSiteTag;
import com.cloudbees.groovy.cps.sandbox.Invoker;
import edu.umd.cs.findbugs.annotations.NonNull;
+import groovy.lang.GString;
import java.util.Collection;
import java.util.Collections;
import org.codehaus.groovy.runtime.InvokerHelper;
@@ -64,6 +65,9 @@ public class MethodPointerBlock implements CallSiteBlock {
* Obtain a method pointer, which is really just a {@link MethodClosure}.
*/
public Next done(Object methodName) {
+ if (methodName instanceof GString) {
+ methodName = methodName.toString();
+ }
return k.receive(e.getInvoker().contextualize(MethodPointerBlock.this).methodPointer(lhs, (String)methodName));
}
diff --git a/lib/src/test/java/com/cloudbees/groovy/cps/sandbox/SandboxInvokerTest.java b/lib/src/test/java/com/cloudbees/groovy/cps/sandbox/SandboxInvokerTest.java
index 3848bd36..9a374ec1 100644
--- a/lib/src/test/java/com/cloudbees/groovy/cps/sandbox/SandboxInvokerTest.java
+++ b/lib/src/test/java/com/cloudbees/groovy/cps/sandbox/SandboxInvokerTest.java
@@ -671,4 +671,19 @@ public class SandboxInvokerTest extends AbstractGroovyCpsTest {
"LinkedHashMap.asBoolean()");
}
+ @Test public void dynamicMethodPointer() throws Throwable {
+ assertIntercept(
+ "def method3() {\n" +
+ " true\n" +
+ "}\n" +
+ "def mp = this.&/method${1 + 2}/\n" +
+ "mp()",
+ true,
+ "Script1.super(Script1).setBinding(Binding)",
+ "Integer.plus(Integer)",
+ "new GStringImpl(Object[],String[])",
+ "SandboxedMethodClosure.call()",
+ "Script1.method3()");
+ }
+
} I will think about this a bit and either file an issue on https://issues.jenkins.io/ or open a PR with the fix. |
6 tasks
I am closing this, see jenkinsci/workflow-cps-plugin#614. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
When using a
GString
to resolve a method pointer, I am getting the below CCE:To reproduce, all you need to do is to get a pointer using the
obj.&"$method_name"
syntax, e.g., if you have a vars/test.groovy that looks like this:try the below from
Jenkinsfile
:As a workaround, I was able to call
toString()
on theGString
, so for the above code to work, change it todef c = test.&("$action.toString())"
The text was updated successfully, but these errors were encountered: