8321131: Console read line with zero out should zero out underlying buffer in JLine

Reviewed-by: iris, alanb, jlahoda
This commit is contained in:
Naoto Sato 2023-12-04 19:12:25 +00:00
parent 155abc576a
commit bd04f91e91
3 changed files with 16 additions and 3 deletions

View File

@ -67,6 +67,9 @@ public class JdkConsoleProviderImpl implements JdkConsoleProvider {
* public Console class.
*/
private static class JdkConsoleImpl implements JdkConsole {
private final Terminal terminal;
private volatile LineReader jline;
@Override
public PrintWriter writer() {
return terminal.writer();
@ -110,6 +113,8 @@ public class JdkConsoleProviderImpl implements JdkConsoleProvider {
return jline.readLine(fmt.formatted(args), '\0').toCharArray();
} catch (EndOfFileException eofe) {
return null;
} finally {
jline.getBuffer().zeroOut();
}
}
@ -128,9 +133,6 @@ public class JdkConsoleProviderImpl implements JdkConsoleProvider {
return terminal.encoding();
}
private final Terminal terminal;
private volatile LineReader jline;
public JdkConsoleImpl(Terminal terminal) {
this.terminal = terminal;
}

View File

@ -84,4 +84,8 @@ public interface Buffer {
void copyFrom(Buffer buffer);
// JDK specific modification
default void zeroOut() {
throw new UnsupportedOperationException();
}
}

View File

@ -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;
@ -369,4 +370,10 @@ public class BufferImpl implements Buffer
g1 += l;
}
}
// JDK specific modification
@Override
public void zeroOut() {
Arrays.fill(buffer, 0);
}
}