From 0004eef1303a7b2b7b4cbabcabe9def12ecd6ec4 Mon Sep 17 00:00:00 2001 From: sherman Date: Fri, 11 Feb 2011 17:09:35 -0800 Subject: [PATCH] 6996192: Console.readPassword race: input echo off must be prior to writing prompt Summary: To turn off echo before prompt Reviewed-by: alanb --- src/share/classes/java/io/Console.java | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/share/classes/java/io/Console.java b/src/share/classes/java/io/Console.java index 783dafd28..9bfbaf004 100644 --- a/src/share/classes/java/io/Console.java +++ b/src/share/classes/java/io/Console.java @@ -308,17 +308,29 @@ public final class Console implements Flushable char[] passwd = null; synchronized (writeLock) { synchronized(readLock) { - if (fmt.length() != 0) - pw.format(fmt, args); try { echoOff = echo(false); - passwd = readline(true); } catch (IOException x) { throw new IOError(x); + } + IOError ioe = null; + try { + if (fmt.length() != 0) + pw.format(fmt, args); + passwd = readline(true); + } catch (IOException x) { + ioe = new IOError(x); } finally { try { echoOff = echo(true); - } catch (IOException xx) {} + } catch (IOException x) { + if (ioe == null) + ioe = new IOError(x); + else + ioe.addSuppressed(x); + } + if (ioe != null) + throw ioe; } pw.println(); } -- GitLab