Skip to content

Commit 93f7a8c

Browse files
committed
8320798: Console read line with zero out should zero out underlying buffer
Reviewed-by: mdoerr Backport-of: 48c847836e44aec2d5be4aaa3040dffc9d95fad5
1 parent dc374f6 commit 93f7a8c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/java.base/share/classes/java/io/Console.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,10 @@ else if (rcb[len-1] == '\n') {
426426
System.arraycopy(rcb, 0, b, 0, len);
427427
if (zeroOut) {
428428
Arrays.fill(rcb, 0, len, ' ');
429+
if (reader instanceof LineReader) {
430+
LineReader lr = (LineReader)reader;
431+
lr.zeroOut();
432+
}
429433
}
430434
}
431435
return b;
@@ -450,6 +454,12 @@ class LineReader extends Reader {
450454
nextChar = nChars = 0;
451455
leftoverLF = false;
452456
}
457+
public void zeroOut() throws IOException {
458+
if (in instanceof StreamDecoder) {
459+
StreamDecoder sd = (StreamDecoder)in;
460+
sd.fillZeroToPosition();
461+
}
462+
}
453463
public void close () {}
454464
public boolean ready() throws IOException {
455465
//in.ready synchronizes on readLock already

src/java.base/share/classes/sun/nio/cs/StreamDecoder.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.nio.*;
3333
import java.nio.channels.*;
3434
import java.nio.charset.*;
35+
import java.util.Arrays;
3536

3637
public class StreamDecoder extends Reader
3738
{
@@ -199,6 +200,16 @@ private boolean isOpen() {
199200
return !closed;
200201
}
201202

203+
public void fillZeroToPosition() throws IOException {
204+
Object lock = this.lock;
205+
synchronized (lock) {
206+
lockedFillZeroToPosition();
207+
}
208+
}
209+
210+
private void lockedFillZeroToPosition() {
211+
Arrays.fill(bb.array(), bb.arrayOffset(), bb.arrayOffset() + bb.position(), (byte)0);
212+
}
202213

203214
// -- Charset-based stream decoder impl --
204215

0 commit comments

Comments
 (0)