summaryrefslogtreecommitdiffstats
path: root/base/common
diff options
context:
space:
mode:
authorAbhishek Koneru <akoneru@redhat.com>2012-06-29 16:08:04 -0400
committerAde Lee <alee@redhat.com>2012-07-06 00:56:33 -0400
commit759d54747b779a1cb11f1b9fbfe8166e62dde03d (patch)
treeb9164f3213d6a0923e8293772fb8362849f327b6 /base/common
parent9ce810c0b2fef9f70178dbeee8a3523755a2a260 (diff)
downloadpki-759d54747b779a1cb11f1b9fbfe8166e62dde03d.tar.gz
pki-759d54747b779a1cb11f1b9fbfe8166e62dde03d.tar.xz
pki-759d54747b779a1cb11f1b9fbfe8166e62dde03d.zip
Coverity CATCH_REXCEPTION and UNREAD_FIELD_CASES
Diffstat (limited to 'base/common')
-rw-r--r--base/common/src/com/netscape/certsrv/base/MessageFormatter.java102
-rw-r--r--base/common/src/com/netscape/cmscore/apps/CMSEngine.java10
-rw-r--r--base/common/src/com/netscape/cmscore/cert/CertUtils.java49
-rw-r--r--base/common/src/com/netscape/cmscore/connector/LocalConnector.java1
-rw-r--r--base/common/src/com/netscape/cmscore/ldap/LdapPredicateParser.java1
-rw-r--r--base/common/src/com/netscape/cmscore/policy/PolicyPredicateParser.java1
-rw-r--r--base/common/src/com/netscape/cmscore/security/PWCBsdr.java7
-rw-r--r--base/common/src/com/netscape/cmscore/security/PWUtil.java65
-rw-r--r--base/common/src/com/netscape/cmscore/security/PWsdrCache.java80
9 files changed, 154 insertions, 162 deletions
diff --git a/base/common/src/com/netscape/certsrv/base/MessageFormatter.java b/base/common/src/com/netscape/certsrv/base/MessageFormatter.java
index 40275b516..f573a227e 100644
--- a/base/common/src/com/netscape/certsrv/base/MessageFormatter.java
+++ b/base/common/src/com/netscape/certsrv/base/MessageFormatter.java
@@ -88,67 +88,63 @@ public class MessageFormatter {
String localizedFormat = null;
try {
- try {
- // if you are worried about the efficiency of the
- // following line, dont worry. ResourceBundle has
- // an internal cache. So resource bundle wont be
- // instantiated everytime you call toString().
+ // if you are worried about the efficiency of the
+ // following line, dont worry. ResourceBundle has
+ // an internal cache. So resource bundle wont be
+ // instantiated everytime you call toString().
- localizedFormat = ResourceBundle.getBundle(
- resourceBundleBaseName, locale).getString(formatString);
- } catch (MissingResourceException e) {
- return formatString;
+ localizedFormat = ResourceBundle.getBundle(
+ resourceBundleBaseName, locale).getString(formatString);
+ } catch (MissingResourceException e) {
+ return formatString;
- }
- Object[] localizedParams = params;
- Object[] localeArg = null;
-
- if (params != null) {
- for (int i = 0; i < params.length; ++i) {
- if (!(params[i] instanceof String) ||
- !(params[i] instanceof Date) ||
- !(params[i] instanceof Number)) {
- if (localizedParams == params) {
+ }
+ Object[] localizedParams = params;
+ Object[] localeArg = null;
+
+ if (params != null) {
+ for (int i = 0; i < params.length; ++i) {
+ if (!(params[i] instanceof String) ||
+ !(params[i] instanceof Date) ||
+ !(params[i] instanceof Number)) {
+ if (localizedParams == params) {
+
+ // only done once
+ // NB if the following variant of cloning code is used
+ // localizedParams = (Object [])mParams.clone();
+ // it causes ArrayStoreException in
+ // localizedParams[i] = params[i].toString();
+ // below
+
+ localizedParams = new Object[params.length];
+ System.arraycopy(params, 0, localizedParams, 0,
+ params.length);
+ }
+ try {
+ Method toStringMethod = params[i].getClass().getMethod(
+ "toString", toStringSignature);
+ if (localeArg == null) {
// only done once
- // NB if the following variant of cloning code is used
- // localizedParams = (Object [])mParams.clone();
- // it causes ArrayStoreException in
- // localizedParams[i] = params[i].toString();
- // below
-
- localizedParams = new Object[params.length];
- System.arraycopy(params, 0, localizedParams, 0,
- params.length);
- }
- try {
- Method toStringMethod = params[i].getClass().getMethod(
- "toString", toStringSignature);
-
- if (localeArg == null) {
- // only done once
- localeArg = new Object[] { locale };
- }
- localizedParams[i] = toStringMethod.invoke(
- params[i], localeArg);
- } catch (Exception e) {
- // no method for localization, fall back
- localizedParams[i] = params[i].toString();
+ localeArg = new Object[] { locale };
}
+ localizedParams[i] = toStringMethod.invoke(
+ params[i], localeArg);
+ } catch (Exception e) {
+ // no method for localization, fall back
+ localizedParams[i] = params[i].toString();
}
}
}
- try {
- // XXX - runtime exception may be raised by the following function
- MessageFormat format = new MessageFormat(localizedFormat);
-
- return format.format(localizedParams);
- } catch (IllegalArgumentException e) {
- // XXX - for now, we just print the unformatted message
- // if the exception is raised
- return localizedFormat;
- }
- } catch (Exception e) {
+ }
+ try {
+ // XXX - runtime exception may be raised by the following function
+ MessageFormat format = new MessageFormat(localizedFormat);
+
+ return format.format(localizedParams);
+ } catch (IllegalArgumentException e) {
+ // XXX - for now, we just print the unformatted message
+ // if the exception is raised
return localizedFormat;
}
}
diff --git a/base/common/src/com/netscape/cmscore/apps/CMSEngine.java b/base/common/src/com/netscape/cmscore/apps/CMSEngine.java
index cbdfee8fc..13a8bb6bf 100644
--- a/base/common/src/com/netscape/cmscore/apps/CMSEngine.java
+++ b/base/common/src/com/netscape/cmscore/apps/CMSEngine.java
@@ -531,8 +531,9 @@ public class CMSEngine implements ICMSEngine {
/**
* Parse server.xml to get the ports and IPs
+ * @throws EBaseException
*/
- private void parseServerXML() {
+ private void parseServerXML() throws EBaseException {
try {
String instanceRoot = mConfig.getString("instanceRoot");
String path = instanceRoot + File.separator + "conf" + File.separator + SERVER_XML;
@@ -628,6 +629,7 @@ public class CMSEngine implements ICMSEngine {
} catch (Exception e) {
CMS.debug("CMSEngine: parseServerXML exception: " + e.toString());
+ throw new EBaseException("CMSEngine: Cannot parse the configuration file. " + e.toString());
}
}
@@ -1586,8 +1588,10 @@ public class CMSEngine implements ICMSEngine {
process.waitFor();
- } catch (Exception e) {
-
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
}
} // end shutdownHttpServer
diff --git a/base/common/src/com/netscape/cmscore/cert/CertUtils.java b/base/common/src/com/netscape/cmscore/cert/CertUtils.java
index ee1e1568c..b7942e5a1 100644
--- a/base/common/src/com/netscape/cmscore/cert/CertUtils.java
+++ b/base/common/src/com/netscape/cmscore/cert/CertUtils.java
@@ -28,6 +28,7 @@ import java.security.cert.CertificateEncodingException;
import java.security.cert.CertificateException;
import java.security.cert.CertificateExpiredException;
import java.security.cert.CertificateNotYetValidException;
+import java.security.cert.CertificateParsingException;
import java.security.cert.X509CRL;
import java.security.cert.X509Certificate;
import java.util.Arrays;
@@ -453,7 +454,7 @@ public class CertUtils {
return ((recentCert == currentCert) ? null : recentCert);
}
- public static String getCertType(X509CertImpl cert) {
+ public static String getCertType(X509CertImpl cert) throws CertificateParsingException, IOException {
StringBuffer sb = new StringBuffer();
if (isSigningCert(cert))
@@ -465,27 +466,24 @@ public class CertUtils {
}
// Is is object signing cert?
- try {
- CertificateExtensions extns = (CertificateExtensions)
- cert.get(X509CertImpl.NAME + "." +
- X509CertImpl.INFO + "." +
- X509CertInfo.EXTENSIONS);
-
- if (extns != null) {
- NSCertTypeExtension nsExtn = (NSCertTypeExtension)
- extns.get(NSCertTypeExtension.NAME);
-
- if (nsExtn != null) {
- String nsType = getNSExtensionInfo(nsExtn);
-
- if (nsType != null) {
- if (sb.length() > 0)
- sb.append(" ");
- sb.append(nsType);
- }
+ CertificateExtensions extns = (CertificateExtensions)
+ cert.get(X509CertImpl.NAME + "." +
+ X509CertImpl.INFO + "." +
+ X509CertInfo.EXTENSIONS);
+
+ if (extns != null) {
+ NSCertTypeExtension nsExtn = (NSCertTypeExtension)
+ extns.get(NSCertTypeExtension.NAME);
+
+ if (nsExtn != null) {
+ String nsType = getNSExtensionInfo(nsExtn);
+
+ if (nsType != null) {
+ if (sb.length() > 0)
+ sb.append(" ");
+ sb.append(nsType);
}
}
- } catch (Exception e) {
}
return (sb.length() > 0) ? sb.toString() : null;
}
@@ -793,14 +791,21 @@ public class CertUtils {
// if the OID isn't valid (ex. n.n) the error isn't caught til
// encoding time leaving a bad request in the request queue.
+ DerOutputStream derOut = null;
try {
- DerOutputStream derOut = new DerOutputStream();
+ derOut = new DerOutputStream();
derOut.putOID(oid);
new ObjectIdentifier(new DerInputStream(derOut.toByteArray()));
} catch (Exception e) {
throw new EBaseException(CMS.getUserMessage("CMS_BASE_INVALID_ATTR_VALUE",
- attrName, msg1));
+ attrName, msg1));
+ } finally {
+ try {
+ derOut.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
return oid;
}
diff --git a/base/common/src/com/netscape/cmscore/connector/LocalConnector.java b/base/common/src/com/netscape/cmscore/connector/LocalConnector.java
index 9c4825494..ed0d5aa6d 100644
--- a/base/common/src/com/netscape/cmscore/connector/LocalConnector.java
+++ b/base/common/src/com/netscape/cmscore/connector/LocalConnector.java
@@ -36,7 +36,6 @@ import com.netscape.certsrv.request.RequestStatus;
import com.netscape.cmscore.util.Debug;
public class LocalConnector implements IConnector {
- ILogger mLogger = CMS.getLogger();
ICertAuthority mSource = null;
IAuthority mDest = null;
Hashtable<String, IRequest> mSourceReqs = new Hashtable<String, IRequest>();
diff --git a/base/common/src/com/netscape/cmscore/ldap/LdapPredicateParser.java b/base/common/src/com/netscape/cmscore/ldap/LdapPredicateParser.java
index 8c2b730d5..699877ffa 100644
--- a/base/common/src/com/netscape/cmscore/ldap/LdapPredicateParser.java
+++ b/base/common/src/com/netscape/cmscore/ldap/LdapPredicateParser.java
@@ -262,7 +262,6 @@ class PredicateTokenizer {
int currentIndex;
int endOfString;
String nextToken;
- boolean first;
public PredicateTokenizer(String predString) {
input = predString;
diff --git a/base/common/src/com/netscape/cmscore/policy/PolicyPredicateParser.java b/base/common/src/com/netscape/cmscore/policy/PolicyPredicateParser.java
index 09316ceff..849417869 100644
--- a/base/common/src/com/netscape/cmscore/policy/PolicyPredicateParser.java
+++ b/base/common/src/com/netscape/cmscore/policy/PolicyPredicateParser.java
@@ -265,7 +265,6 @@ class PredicateTokenizer {
int currentIndex;
int endOfString;
String nextToken;
- boolean first;
public PredicateTokenizer(String predString) {
input = predString;
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;
}
}