Skip to content

Commit 5f10844

Browse files
committed
copy bytes since it might be a shared (unsafe) buffer from RubyString
fixes #150
1 parent f03bcc1 commit 5f10844

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/main/java/org/jruby/ext/openssl/StringHelper.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ static byte[] readX509PEM(final byte[] bytes, final int offset, final int length
101101
catch (IOException e) {
102102
// this is not PEM encoded, let's use the default argument
103103
}
104-
return bytes;
104+
if ( offset == 0 && length == bytes.length ) return bytes;
105+
byte[] copy = new byte[length];
106+
System.arraycopy(bytes, offset, copy, 0, length);
107+
return copy;
105108
}
106109

107110
static RubyString readPossibleDERInput(final ThreadContext context, final IRubyObject arg) {

0 commit comments

Comments
 (0)