From 0c3f184c762ed0b5cce42d5b33f8c1b8bcb46658 Mon Sep 17 00:00:00 2001 From: Manef Zahra Date: Thu, 1 Feb 2024 21:42:09 -0500 Subject: [PATCH] Throw a runtime error if #binding is called from a C ext module (non-ruby frame) Co-authored-by: Randy Stauner --- src/main/java/org/truffleruby/core/kernel/KernelNodes.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/org/truffleruby/core/kernel/KernelNodes.java b/src/main/java/org/truffleruby/core/kernel/KernelNodes.java index b1da3d150421..7f1f4c655c70 100644 --- a/src/main/java/org/truffleruby/core/kernel/KernelNodes.java +++ b/src/main/java/org/truffleruby/core/kernel/KernelNodes.java @@ -334,6 +334,12 @@ RubyBinding binding(Frame callerFrame, Object self, Object[] rubyArgs, RootCallT @Cached( value = "getAdoptedNode(this).getEncapsulatingSourceSection()", allowUncached = true, neverDefault = false) SourceSection sourceSection) { + final InternalMethod method = RubyArguments.tryGetMethod(callerFrame); + if (method == null || method.getDeclaringModule().toString().equals("Truffle::CExt")) { + throw new RaiseException(getContext(), + coreExceptions().runtimeError("You cannot call Kernel#Binding from a non-ruby frame", this)); + + } needCallerFrame(callerFrame, target); return BindingNodes.createBinding(getContext(), getLanguage(), callerFrame.materialize(), sourceSection); }