Skip to main content
Sign in
Snippets Groups Projects
Commit 48c84783 authored by Goetz Lindenmaier's avatar Goetz Lindenmaier
Browse files

8320798: Console read line with zero out should zero out underlying buffer

Reviewed-by: mbaesken
Backport-of: d568562966e9a2020704eee3d67b8a106f647d9c
parent 5653d2d1
No related branches found
No related tags found
No related merge requests found
...@@ -445,6 +445,9 @@ public final class Console implements Flushable ...@@ -445,6 +445,9 @@ public final class Console implements Flushable
System.arraycopy(rcb, 0, b, 0, len); System.arraycopy(rcb, 0, b, 0, len);
if (zeroOut) { if (zeroOut) {
Arrays.fill(rcb, 0, len, ' '); Arrays.fill(rcb, 0, len, ' ');
if (reader instanceof LineReader lr) {
lr.zeroOut();
}
} }
} }
return b; return b;
...@@ -469,6 +472,11 @@ public final class Console implements Flushable ...@@ -469,6 +472,11 @@ public final class Console implements Flushable
nextChar = nChars = 0; nextChar = nChars = 0;
leftoverLF = false; leftoverLF = false;
} }
public void zeroOut() throws IOException {
if (in instanceof StreamDecoder sd) {
sd.fillZeroToPosition();
}
}
public void close () {} public void close () {}
public boolean ready() throws IOException { public boolean ready() throws IOException {
//in.ready synchronizes on readLock already //in.ready synchronizes on readLock already
... ...
......
...@@ -42,6 +42,7 @@ import java.nio.charset.CoderResult; ...@@ -42,6 +42,7 @@ import java.nio.charset.CoderResult;
import java.nio.charset.CodingErrorAction; import java.nio.charset.CodingErrorAction;
import java.nio.charset.IllegalCharsetNameException; import java.nio.charset.IllegalCharsetNameException;
import java.nio.charset.UnsupportedCharsetException; import java.nio.charset.UnsupportedCharsetException;
import java.util.Arrays;
public class StreamDecoder extends Reader { public class StreamDecoder extends Reader {
...@@ -212,6 +213,16 @@ public class StreamDecoder extends Reader { ...@@ -212,6 +213,16 @@ public class StreamDecoder extends Reader {
return !closed; return !closed;
} }
public void fillZeroToPosition() throws IOException {
Object lock = this.lock;
synchronized (lock) {
lockedFillZeroToPosition();
}
}
private void lockedFillZeroToPosition() {
Arrays.fill(bb.array(), bb.arrayOffset(), bb.arrayOffset() + bb.position(), (byte)0);
}
// -- Charset-based stream decoder impl -- // -- Charset-based stream decoder impl --
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment