Skip to content

Commit cd89254

Browse files
manefzrwstauner
andcommitted
Throw a runtime error if #binding is called from a
C ext module (non-ruby frame) Co-authored-by: Randy Stauner <randy.stauner@shopify.com>
1 parent 90bfaa0 commit cd89254

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Compatibility:
4444
* Do not autosplat a proc that accepts a single positional argument and keywords (#3039, @andrykonchin).
4545
* Support passing anonymous * and ** parameters as method call arguments (#3039, @andrykonchin).
4646
* Handle either positional or keywords arguments by default in `Struct.new` (#3039, @rwstauner).
47+
* Make `Kernel#binding` raise a RuntimeError when called from a non-Ruby frame (such as a method defined in C) (#3039, @rwstauner, @manefz)
4748

4849
Performance:
4950

Diff for: src/main/java/org/truffleruby/core/kernel/KernelNodes.java

+6
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,12 @@ RubyBinding binding(Frame callerFrame, Object self, Object[] rubyArgs, RootCallT
334334
@Cached(
335335
value = "getAdoptedNode(this).getEncapsulatingSourceSection()",
336336
allowUncached = true, neverDefault = false) SourceSection sourceSection) {
337+
final InternalMethod method = RubyArguments.tryGetMethod(callerFrame);
338+
if (method == null || method.getDeclaringModule().toString().equals("Truffle::CExt")) {
339+
throw new RaiseException(getContext(),
340+
coreExceptions().runtimeError("You cannot call Kernel#Binding from a non-ruby frame", this));
341+
342+
}
337343
needCallerFrame(callerFrame, target);
338344
return BindingNodes.createBinding(getContext(), getLanguage(), callerFrame.materialize(), sourceSection);
339345
}

0 commit comments

Comments
 (0)