diff options
author | Abhishek Koneru <akoneru@redhat.com> | 2012-06-29 16:08:04 -0400 |
---|---|---|
committer | Ade Lee <alee@redhat.com> | 2012-07-06 00:56:33 -0400 |
commit | 759d54747b779a1cb11f1b9fbfe8166e62dde03d (patch) | |
tree | b9164f3213d6a0923e8293772fb8362849f327b6 /base/common/src/com/netscape/cmscore/security | |
parent | 9ce810c0b2fef9f70178dbeee8a3523755a2a260 (diff) | |
download | pki-759d54747b779a1cb11f1b9fbfe8166e62dde03d.tar.gz pki-759d54747b779a1cb11f1b9fbfe8166e62dde03d.tar.xz pki-759d54747b779a1cb11f1b9fbfe8166e62dde03d.zip |
Coverity CATCH_REXCEPTION and UNREAD_FIELD_CASES
Diffstat (limited to 'base/common/src/com/netscape/cmscore/security')
3 files changed, 71 insertions, 81 deletions
diff --git a/base/common/src/com/netscape/cmscore/security/PWCBsdr.java b/base/common/src/com/netscape/cmscore/security/PWCBsdr.java index 0ff50668c..a62a8561d 100644 --- a/base/common/src/com/netscape/cmscore/security/PWCBsdr.java +++ b/base/common/src/com/netscape/cmscore/security/PWCBsdr.java @@ -17,9 +17,6 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.security; -import java.io.InputStream; -import java.io.OutputStream; - import org.mozilla.jss.util.Password; import org.mozilla.jss.util.PasswordCallback; import org.mozilla.jss.util.PasswordCallbackInfo; @@ -36,8 +33,6 @@ import com.netscape.cmscore.base.JDialogPasswordCallback; */ public class PWCBsdr implements PasswordCallback { - InputStream in = null; - OutputStream out = null; String mprompt = ""; boolean firsttime = true; private PasswordCallback mCB = null; @@ -49,8 +44,6 @@ public class PWCBsdr implements PasswordCallback { } public PWCBsdr(String prompt) { - in = System.in; - out = System.out; mprompt = prompt; /* to get the test program work diff --git a/base/common/src/com/netscape/cmscore/security/PWUtil.java b/base/common/src/com/netscape/cmscore/security/PWUtil.java index fa0de3c4b..78678b98b 100644 --- a/base/common/src/com/netscape/cmscore/security/PWUtil.java +++ b/base/common/src/com/netscape/cmscore/security/PWUtil.java @@ -21,53 +21,48 @@ import org.mozilla.jss.util.Password; import org.mozilla.jss.util.PasswordCallback; public class PWUtil { - public static Password - readPasswordFromStream() - throws PasswordCallback.GiveUpException { + + public static Password readPasswordFromStream() throws PasswordCallback.GiveUpException { StringBuffer buf = new StringBuffer(); String passwordString = ""; int c; - + // System.out.println( "about to do read" ); try { - // System.out.println( "about to do read" ); - try { - while ((c = System.in.read()) != -1) { - char ch = (char) c; + while ((c = System.in.read()) != -1) { + char ch = (char) c; - // System.out.println( "read [" + ch + "]" ); - // System.out.println( "char is [" + ch + "]" ); - if (ch != '\r') { - if (ch != '\n') { - buf.append(ch); - } else { - passwordString = buf.toString(); - buf.setLength(0); - break; - } + // System.out.println( "read [" + ch + "]" ); + // System.out.println( "char is [" + ch + "]" ); + if (ch != '\r') { + if (ch != '\n') { + buf.append(ch); + } else { + passwordString = buf.toString(); + buf.setLength(0); + break; } } - } catch (Exception e) { - System.out.println("READ EXCEPTION"); - } - - // memory problem? - // String passwordString = in.readLine(); - // System.out.println( "done read" ); - // System.out.println( " password recieved is [" - // + passwordString + "]" ); - if (passwordString == null) { - throw new PasswordCallback.GiveUpException(); } + } catch (Exception e) { + System.out.println("READ EXCEPTION"); + } - if (passwordString.equals("")) { - throw new PasswordCallback.GiveUpException(); - } + // memory problem? + // String passwordString = in.readLine(); + // System.out.println( "done read" ); + // System.out.println( " password recieved is [" + // + passwordString + "]" ); + if (passwordString == null) { + throw new PasswordCallback.GiveUpException(); + } - // System.out.println( "returning pw" ); - return (new Password(passwordString.toCharArray())); - } catch (Exception e) { + if (passwordString.equals("")) { throw new PasswordCallback.GiveUpException(); } + + // System.out.println( "returning pw" ); + return (new Password(passwordString.toCharArray())); + } } diff --git a/base/common/src/com/netscape/cmscore/security/PWsdrCache.java b/base/common/src/com/netscape/cmscore/security/PWsdrCache.java index b0445bd6d..810605d41 100644 --- a/base/common/src/com/netscape/cmscore/security/PWsdrCache.java +++ b/base/common/src/com/netscape/cmscore/security/PWsdrCache.java @@ -542,50 +542,52 @@ public class PWsdrCache { return ((File.separator).equals("\\")); } - public static boolean exec(String cmd) throws EBaseException { + public static boolean exec(String cmd) throws IOException { + String cmds[] = null; + + if (isNT()) { + // NT + cmds = new String[3]; + cmds[0] = "cmd"; + cmds[1] = "/c"; + cmds[2] = cmd; + } else { + // UNIX + cmds = new String[3]; + cmds[0] = "/bin/sh"; + cmds[1] = "-c"; + cmds[2] = cmd; + } + Process process = null; try { - String cmds[] = null; - - if (isNT()) { - // NT - cmds = new String[3]; - cmds[0] = "cmd"; - cmds[1] = "/c"; - cmds[2] = cmd; - } else { - // UNIX - cmds = new String[3]; - cmds[0] = "/bin/sh"; - cmds[1] = "-c"; - cmds[2] = cmd; - } - Process process = Runtime.getRuntime().exec(cmds); - + process = Runtime.getRuntime().exec(cmds); process.waitFor(); + } catch (IOException e) { + throw e; + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } - if (process.exitValue() == 0) { + if (process != null && process.exitValue() == 0) { - /** - * pOut = new BufferedReader( - * new InputStreamReader(process.getInputStream())); - * while ((l = pOut.readLine()) != null) { - * System.out.println(l); - * } - **/ - return true; - } else { + /** + * pOut = new BufferedReader( + * new InputStreamReader(process.getInputStream())); + * while ((l = pOut.readLine()) != null) { + * System.out.println(l); + * } + **/ + return true; + } else { - /** - * pOut = new BufferedReader( - * new InputStreamReader(process.getErrorStream())); - * l = null; - * while ((l = pOut.readLine()) != null) { - * System.out.println(l); - * } - **/ - return false; - } - } catch (Exception e) { + /** + * pOut = new BufferedReader( + * new InputStreamReader(process.getErrorStream())); + * l = null; + * while ((l = pOut.readLine()) != null) { + * System.out.println(l); + * } + **/ return false; } } |