Skip to content

Commit

Permalink
[Truffle] Don't taint from self in String#[](String).
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvdrum committed Mar 30, 2015
1 parent 7ca2f63 commit bd06055
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
1 change: 0 additions & 1 deletion spec/truffle/tags/core/string/element_reference_tags.txt
@@ -1,4 +1,3 @@
fails:String#[] with Range calls to_int on range arguments
fails:String#[] with Range works with Range subclasses
fails:String#[] with Regexp, index returns nil if there is no capture for the given index
fails:String#[] with String taints resulting strings when other is tainted
1 change: 0 additions & 1 deletion spec/truffle/tags/core/string/slice_tags.txt
@@ -1,7 +1,6 @@
fails:String#slice with Range calls to_int on range arguments
fails:String#slice with Range works with Range subclasses
fails:String#slice with Regexp, index returns nil if there is no capture for the given index
fails:String#slice with String taints resulting strings when other is tainted
fails:String#slice! with index calls to_int on index
fails:String#slice! with index returns the character given by the character index
fails:String#slice! with index, length deletes and returns the substring at idx and the given length
Expand Down
Expand Up @@ -12,6 +12,7 @@

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.ControlFlowException;
import com.oracle.truffle.api.nodes.ExplodeLoop;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.source.SourceSection;
Expand Down Expand Up @@ -70,6 +71,8 @@ public Object execute(VirtualFrame frame) {

try {
result = method.executeRubyBasicObject(frame);
} catch (DoNotTaintException e) {
return e.getResult();
} catch (UnexpectedResultException e) {
throw new UnsupportedOperationException(e);
}
Expand Down Expand Up @@ -97,4 +100,18 @@ public Object execute(VirtualFrame frame) {

return result;
}

public static class DoNotTaintException extends ControlFlowException {
private static final long serialVersionUID = 5321304910918469059L;

private final Object result;

public DoNotTaintException(Object result) {
this.result = result;
}

public Object getResult() {
return result;
}
}
}
Expand Up @@ -612,7 +612,7 @@ public Object slice(VirtualFrame frame, RubyString string, RubyString matchStr,
dupNode = insert(DispatchHeadNodeFactory.createMethodCall(getContext()));
}

return dupNode.call(frame, matchStr, "dup", null);
throw new TaintResultNode.DoNotTaintException(dupNode.call(frame, matchStr, "dup", null));
}

return nil();
Expand Down

0 comments on commit bd06055

Please sign in to comment.