From 381f494754d21166b4c0e6ea5af723d180e76ffc Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Thu, 7 Aug 2014 20:17:51 +0000 Subject: [PATCH] SU3File: Fix NPE on EOF reading input --- core/java/src/net/i2p/crypto/SU3File.java | 28 +++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/core/java/src/net/i2p/crypto/SU3File.java b/core/java/src/net/i2p/crypto/SU3File.java index 30e172d4db..455e43d628 100644 --- a/core/java/src/net/i2p/crypto/SU3File.java +++ b/core/java/src/net/i2p/crypto/SU3File.java @@ -619,7 +619,12 @@ public class SU3File { try { while (keypw.length() < 6) { System.out.print("Enter password for key \"" + signerName + "\": "); - keypw = DataHelper.readLine(System.in).trim(); + keypw = DataHelper.readLine(System.in); + if (keypw == null) { + System.out.println("\nEOF reading password"); + return false; + } + keypw = keypw.trim(); if (keypw.length() > 0 && keypw.length() < 6) System.out.println("Key password must be at least 6 characters"); } @@ -690,7 +695,12 @@ public class SU3File { try { while (keypw.length() < 6) { System.out.print("Enter password for key \"" + signerName + "\": "); - keypw = DataHelper.readLine(System.in).trim(); + keypw = DataHelper.readLine(System.in); + if (keypw == null) { + System.out.println("\nEOF reading password"); + return false; + } + keypw = keypw.trim(); if (keypw.length() > 0 && keypw.length() < 6) System.out.println("Key password must be at least 6 characters"); } @@ -784,11 +794,21 @@ public class SU3File { try { while (alias.length() == 0) { System.out.print("Enter key name (example@mail.i2p): "); - alias = DataHelper.readLine(System.in).trim(); + alias = DataHelper.readLine(System.in); + if (alias == null) { + System.out.println("\nEOF reading key name"); + return false; + } + alias = alias.trim(); } while (keypw.length() < 6) { System.out.print("Enter new key password: "); - keypw = DataHelper.readLine(System.in).trim(); + keypw = DataHelper.readLine(System.in); + if (keypw == null) { + System.out.println("\nEOF reading password"); + return false; + } + keypw = keypw.trim(); if (keypw.length() > 0 && keypw.length() < 6) System.out.println("Key password must be at least 6 characters"); } -- GitLab