From c66527ff923ee23327c24816573f7a4fb669ef2b Mon Sep 17 00:00:00 2001 From: Goetz Lindenmaier Date: Tue, 19 Dec 2023 13:45:38 +0100 Subject: [PATCH] 8320798: Console read line with zero out should zero out when throwing exception --- .../share/classes/jdk/internal/io/JdkConsoleImpl.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/java.base/share/classes/jdk/internal/io/JdkConsoleImpl.java b/src/java.base/share/classes/jdk/internal/io/JdkConsoleImpl.java index 370fc73fcd0f4..247545f8721e9 100644 --- a/src/java.base/share/classes/jdk/internal/io/JdkConsoleImpl.java +++ b/src/java.base/share/classes/jdk/internal/io/JdkConsoleImpl.java @@ -119,8 +119,17 @@ public char[] readPassword(String fmt, Object ... args) { else ioe.addSuppressed(x); } - if (ioe != null) + if (ioe != null) { + java.util.Arrays.fill(passwd, ' '); + try { + if (reader instanceof LineReader lr) { + lr.zeroOut(); + } + } catch (IOException x) { + // ignore + } throw ioe; + } } pw.println(); }