Skip to content

Commit bd06055

Browse files
committed
[Truffle] Don't taint from self in String#[](String).
1 parent 7ca2f63 commit bd06055

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
fails:String#[] with Range calls to_int on range arguments
22
fails:String#[] with Range works with Range subclasses
33
fails:String#[] with Regexp, index returns nil if there is no capture for the given index
4-
fails:String#[] with String taints resulting strings when other is tainted

spec/truffle/tags/core/string/slice_tags.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
fails:String#slice with Range calls to_int on range arguments
22
fails:String#slice with Range works with Range subclasses
33
fails:String#slice with Regexp, index returns nil if there is no capture for the given index
4-
fails:String#slice with String taints resulting strings when other is tainted
54
fails:String#slice! with index calls to_int on index
65
fails:String#slice! with index returns the character given by the character index
76
fails:String#slice! with index, length deletes and returns the substring at idx and the given length

truffle/src/main/java/org/jruby/truffle/nodes/cast/TaintResultNode.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import com.oracle.truffle.api.CompilerDirectives;
1414
import com.oracle.truffle.api.frame.VirtualFrame;
15+
import com.oracle.truffle.api.nodes.ControlFlowException;
1516
import com.oracle.truffle.api.nodes.ExplodeLoop;
1617
import com.oracle.truffle.api.nodes.UnexpectedResultException;
1718
import com.oracle.truffle.api.source.SourceSection;
@@ -70,6 +71,8 @@ public Object execute(VirtualFrame frame) {
7071

7172
try {
7273
result = method.executeRubyBasicObject(frame);
74+
} catch (DoNotTaintException e) {
75+
return e.getResult();
7376
} catch (UnexpectedResultException e) {
7477
throw new UnsupportedOperationException(e);
7578
}
@@ -97,4 +100,18 @@ public Object execute(VirtualFrame frame) {
97100

98101
return result;
99102
}
103+
104+
public static class DoNotTaintException extends ControlFlowException {
105+
private static final long serialVersionUID = 5321304910918469059L;
106+
107+
private final Object result;
108+
109+
public DoNotTaintException(Object result) {
110+
this.result = result;
111+
}
112+
113+
public Object getResult() {
114+
return result;
115+
}
116+
}
100117
}

truffle/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ public Object slice(VirtualFrame frame, RubyString string, RubyString matchStr,
612612
dupNode = insert(DispatchHeadNodeFactory.createMethodCall(getContext()));
613613
}
614614

615-
return dupNode.call(frame, matchStr, "dup", null);
615+
throw new TaintResultNode.DoNotTaintException(dupNode.call(frame, matchStr, "dup", null));
616616
}
617617

618618
return nil();

0 commit comments

Comments
 (0)