Skip to content

Commit

Permalink
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
@@ -2649,14 +2649,17 @@ public IRubyObject prepend(ThreadContext context, IRubyObject other) {
*/
@JRubyMethod(name = "crypt")
public RubyString crypt(ThreadContext context, IRubyObject other) {
Encoding ascii8bit = context.runtime.getEncodingService().getAscii8bitEncoding();
RubyString otherStr = other.convertToString();
otherStr.associateEncoding(ascii8bit);
String salt = otherStr.asJavaString();
if (salt.length() < 2) {
if (otherStr.getByteList().length() < 2) {
throw context.runtime.newArgumentError("salt too short(need >=2 bytes)");
}

RubyString result = RubyString.newString(context.runtime,
context.runtime.getPosix().crypt(asJavaString(), salt).toString());
result.associateEncoding(ascii8bit);
result.infectBy(this);
result.infectBy(otherStr);
return result;
1 change: 1 addition & 0 deletions spec/tags/1.8/ruby/core/string/crypt_tags.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
fail:String#crypt returns NULL bytes prepended to the string when the salt contains NULL bytes

0 comments on commit 729acbf

Please sign in to comment.