Skip to content

Commit

Permalink
8321131: Console read line with zero out should zero out underlying b…
Browse files Browse the repository at this point in the history
…uffer in JLine

Reviewed-by: iris, alanb, jlahoda
  • Loading branch information
naotoj committed Dec 4, 2023
1 parent 155abc5 commit bd04f91
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Expand Up @@ -67,6 +67,9 @@ public JdkConsole console(boolean isTTY, Charset charset) {
* public Console class.
*/
private static class JdkConsoleImpl implements JdkConsole {
private final Terminal terminal;
private volatile LineReader jline;

@Override
public PrintWriter writer() {
return terminal.writer();
Expand Down Expand Up @@ -110,6 +113,8 @@ public char[] readPassword(String fmt, Object ... args) {
return jline.readLine(fmt.formatted(args), '\0').toCharArray();
} catch (EndOfFileException eofe) {
return null;
} finally {
jline.getBuffer().zeroOut();
}
}

Expand All @@ -128,9 +133,6 @@ public Charset charset() {
return terminal.encoding();
}

private final Terminal terminal;
private volatile LineReader jline;

public JdkConsoleImpl(Terminal terminal) {
this.terminal = terminal;
}
Expand Down
Expand Up @@ -84,4 +84,8 @@ public interface Buffer {

void copyFrom(Buffer buffer);

// JDK specific modification
default void zeroOut() {
throw new UnsupportedOperationException();
}
}
Expand Up @@ -8,6 +8,7 @@
*/
package jdk.internal.org.jline.reader.impl;

import java.util.Arrays;
import java.util.Objects;

import jdk.internal.org.jline.reader.Buffer;
Expand Down Expand Up @@ -369,4 +370,10 @@ private void moveGapToCursor() {
g1 += l;
}
}

// JDK specific modification
@Override
public void zeroOut() {
Arrays.fill(buffer, 0);
}
}

1 comment on commit bd04f91

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.