summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAbhishek Koneru <akoneru@redhat.com>2012-05-18 17:59:50 -0400
committerAde Lee <alee@redhat.com>2012-05-24 23:09:10 -0400
commitbe23c86db27b7f66ca16a10ae3ef3f043d1d4b27 (patch)
treeba5ed1bbe24889b7d22278093ee66cffc780b42b
parent9db76ed1d1f8969e93aaff320e49662f53688e2e (diff)
downloadpki-be23c86db27b7f66ca16a10ae3ef3f043d1d4b27.tar.gz
pki-be23c86db27b7f66ca16a10ae3ef3f043d1d4b27.tar.xz
pki-be23c86db27b7f66ca16a10ae3ef3f043d1d4b27.zip
Fixes for Coverity Defects of Category : FB.SBSC_USE_STRINGBUFFER_CONCATENATION --Remaining
-rw-r--r--base/common/src/com/netscape/cmscore/realm/ACLEntry.java14
-rw-r--r--base/kra/src/com/netscape/kra/EnrollmentService.java12
-rw-r--r--base/kra/src/com/netscape/kra/KeyRecoveryAuthority.java14
-rw-r--r--base/kra/src/com/netscape/kra/TokenKeyRecoveryService.java6
-rwxr-xr-xbase/silent/src/com/netscape/pkisilent/argparser/ArgParser.java22
-rw-r--r--base/silent/src/com/netscape/pkisilent/common/CMSLDAP.java9
-rw-r--r--base/silent/src/com/netscape/pkisilent/common/ComCrypto.java24
-rw-r--r--base/silent/src/com/netscape/pkisilent/common/ServerInfo.java6
-rw-r--r--base/silent/src/com/netscape/pkisilent/common/Utilities.java28
-rw-r--r--base/util/src/netscape/security/util/ObjectIdentifier.java11
-rw-r--r--base/util/src/netscape/security/x509/Attribute.java9
-rw-r--r--base/util/src/netscape/security/x509/CertificateChain.java6
-rw-r--r--base/util/src/netscape/security/x509/GeneralSubtrees.java6
-rw-r--r--base/util/src/netscape/security/x509/IPAddressName.java15
-rw-r--r--base/util/src/netscape/security/x509/PolicyQualifiers.java9
-rw-r--r--base/util/src/netscape/security/x509/SubjectDirAttributesExtension.java6
16 files changed, 103 insertions, 94 deletions
diff --git a/base/common/src/com/netscape/cmscore/realm/ACLEntry.java b/base/common/src/com/netscape/cmscore/realm/ACLEntry.java
index e05abf0b9..1e13ad682 100644
--- a/base/common/src/com/netscape/cmscore/realm/ACLEntry.java
+++ b/base/common/src/com/netscape/cmscore/realm/ACLEntry.java
@@ -221,23 +221,23 @@ public class ACLEntry {
* @return string representation of this ACLEntry
*/
public String toString() {
- String entry = "";
+ StringBuffer entry = new StringBuffer();
if (isNegative()) {
- entry += "deny (";
+ entry.append("deny (");
} else {
- entry += "allow (";
+ entry.append("allow (");
}
Enumeration<String> e = permissions();
for (; e.hasMoreElements();) {
String p = e.nextElement();
- entry += p;
+ entry.append(p);
if (e.hasMoreElements())
- entry += ",";
+ entry.append(",");
}
- entry += ") " + getAttributeExpressions();
- return entry;
+ entry.append(") " + getAttributeExpressions());
+ return entry.toString();
}
}
diff --git a/base/kra/src/com/netscape/kra/EnrollmentService.java b/base/kra/src/com/netscape/kra/EnrollmentService.java
index 22400cf67..c881decdf 100644
--- a/base/kra/src/com/netscape/kra/EnrollmentService.java
+++ b/base/kra/src/com/netscape/kra/EnrollmentService.java
@@ -834,7 +834,7 @@ public class EnrollmentService implements IService {
return ILogger.SIGNED_AUDIT_EMPTY_VALUE;
}
- String key = "";
+ StringBuffer key = new StringBuffer();
// convert "rawData" into "base64Data"
if (rawData != null) {
@@ -845,16 +845,14 @@ public class EnrollmentService implements IService {
// extract all line separators from the "base64Data"
StringTokenizer st = new StringTokenizer(base64Data, "\r\n");
while (st.hasMoreTokens()) {
- key += st.nextToken();
+ key.append(st.nextToken());
}
}
-
- key = key.trim();
-
- if (key.equals("")) {
+ String checkKey = key.toString().trim();
+ if (checkKey.equals("")) {
return ILogger.SIGNED_AUDIT_EMPTY_VALUE;
} else {
- return key;
+ return checkKey;
}
}
diff --git a/base/kra/src/com/netscape/kra/KeyRecoveryAuthority.java b/base/kra/src/com/netscape/kra/KeyRecoveryAuthority.java
index 6579261f6..8aebebad0 100644
--- a/base/kra/src/com/netscape/kra/KeyRecoveryAuthority.java
+++ b/base/kra/src/com/netscape/kra/KeyRecoveryAuthority.java
@@ -1666,16 +1666,16 @@ public class KeyRecoveryAuthority implements IAuthority, IKeyService, IKeyRecove
// convert "rawData" into "base64Data"
if (rawData != null) {
String base64Data = CMS.BtoA(rawData).trim();
- String key = "";
+ StringBuffer key = new StringBuffer();
// extract all line separators from the "base64Data"
for (int i = 0; i < base64Data.length(); i++) {
if (base64Data.substring(i, i).getBytes() != EOL) {
- key += base64Data.substring(i, i);
+ key.append(base64Data.substring(i, i));
}
}
- return key;
+ return key.toString();
}
return ILogger.SIGNED_AUDIT_EMPTY_VALUE;
@@ -1710,7 +1710,7 @@ public class KeyRecoveryAuthority implements IAuthority, IKeyService, IKeyRecove
}
String key = null;
-
+ StringBuffer tempBuffer = new StringBuffer();
// convert "rawData" into "base64Data"
if (rawData != null) {
String base64Data = null;
@@ -1720,11 +1720,15 @@ public class KeyRecoveryAuthority implements IAuthority, IKeyService, IKeyRecove
// extract all line separators from the "base64Data"
for (int i = 0; i < base64Data.length(); i++) {
if (base64Data.substring(i, i).getBytes() != EOL) {
- key += base64Data.substring(i, i);
+ tempBuffer.append(base64Data.substring(i, i));
}
}
}
+ if (tempBuffer.length() > 0) {
+ key = tempBuffer.toString();
+ }
+
if (key != null) {
key = key.trim();
diff --git a/base/kra/src/com/netscape/kra/TokenKeyRecoveryService.java b/base/kra/src/com/netscape/kra/TokenKeyRecoveryService.java
index 30a23594c..2d53552a0 100644
--- a/base/kra/src/com/netscape/kra/TokenKeyRecoveryService.java
+++ b/base/kra/src/com/netscape/kra/TokenKeyRecoveryService.java
@@ -125,7 +125,7 @@ public class TokenKeyRecoveryService implements IService {
}
public static String normalizeCertStr(String s) {
- String val = "";
+ StringBuffer val = new StringBuffer();
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == '\\') {
@@ -139,9 +139,9 @@ public class TokenKeyRecoveryService implements IService {
} else if (s.charAt(i) == ' ') {
continue;
}
- val += s.charAt(i);
+ val.append(s.charAt(i));
}
- return val;
+ return val.toString();
}
private static String base64Encode(byte[] bytes) throws IOException {
diff --git a/base/silent/src/com/netscape/pkisilent/argparser/ArgParser.java b/base/silent/src/com/netscape/pkisilent/argparser/ArgParser.java
index 29c1c394d..0e3325005 100755
--- a/base/silent/src/com/netscape/pkisilent/argparser/ArgParser.java
+++ b/base/silent/src/com/netscape/pkisilent/argparser/ArgParser.java
@@ -2009,7 +2009,7 @@ public class ArgParser {
s = "Usage: " + synopsisString + "\n";
s += "Options include:\n\n";
for (int i = 0; i < matchList.size(); i++) {
- String optionInfo = "";
+ StringBuffer optionInfo = new StringBuffer();
rec = matchList.get(i);
if (rec.convertCode == 'h' && !helpOptionsEnabled) {
continue;
@@ -2021,33 +2021,33 @@ public class ArgParser {
}
}
for (ndesc = rec.nameList; ndesc != null; ndesc = ndesc.next) {
- optionInfo += ndesc.name;
+ optionInfo.append(ndesc.name);
if (hasOneWordAlias && !ndesc.oneWord) {
- optionInfo += " ";
+ optionInfo.append(" ");
}
if (ndesc.next != null) {
- optionInfo += ",";
+ optionInfo.append(",");
}
}
if (!hasOneWordAlias) {
- optionInfo += " ";
+ optionInfo.append(" ");
}
if (rec.convertCode != 'v' && rec.convertCode != 'h') {
if (rec.valueDesc != null) {
- optionInfo += rec.valueDesc;
+ optionInfo.append(rec.valueDesc);
} else {
if (rec.rangeDesc != null) {
- optionInfo += "<" + rec.valTypeName() + " "
- + rec.rangeDesc + ">";
+ optionInfo.append("<" + rec.valTypeName() + " "
+ + rec.rangeDesc + ">");
} else {
- optionInfo += "<" + rec.valTypeName() + ">";
+ optionInfo.append("<" + rec.valTypeName() + ">");
}
}
}
if (rec.numValues > 1) {
- optionInfo += "X" + rec.numValues;
+ optionInfo.append("X" + rec.numValues);
}
- s += optionInfo;
+ s += optionInfo.toString();
if (rec.helpMsg.length() > 0) {
int pad = helpIndent - optionInfo.length();
if (pad < 2) { //s += '\n';
diff --git a/base/silent/src/com/netscape/pkisilent/common/CMSLDAP.java b/base/silent/src/com/netscape/pkisilent/common/CMSLDAP.java
index cddb630da..ae9bc276e 100644
--- a/base/silent/src/com/netscape/pkisilent/common/CMSLDAP.java
+++ b/base/silent/src/com/netscape/pkisilent/common/CMSLDAP.java
@@ -215,19 +215,18 @@ public class CMSLDAP {
}
private String buildDNString(String s) {
-
- String val = "";
+ StringBuffer val = new StringBuffer();
for (int i = 0; i < s.length(); i++) {
if ((s.charAt(i) == ',') && (s.charAt(i + 1) == ' ')) {
- val += ',';
+ val.append(',');
i++;
continue;
} else {
- val += s.charAt(i);
+ val.append(s.charAt(i));
}
}
- return val;
+ return val.toString();
}
/**
diff --git a/base/silent/src/com/netscape/pkisilent/common/ComCrypto.java b/base/silent/src/com/netscape/pkisilent/common/ComCrypto.java
index e36966de1..2dacaabbf 100644
--- a/base/silent/src/com/netscape/pkisilent/common/ComCrypto.java
+++ b/base/silent/src/com/netscape/pkisilent/common/ComCrypto.java
@@ -291,11 +291,11 @@ public class ComCrypto {
public String normalize(String s) {
- String val = "";
+ StringBuffer val = new StringBuffer();
for (int i = 0; i < s.length(); i++) {
if ((s.charAt(i) == '\\') && (s.charAt(i + 1) == 'n')) {
- val += '\n';
+ val.append('\n');
i++;
continue;
} else if ((s.charAt(i) == '\\') && (s.charAt(i + 1) == 'r')) {
@@ -304,9 +304,9 @@ public class ComCrypto {
} else if (s.charAt(i) == '"') {
continue;
}
- val += s.charAt(i);
+ val.append(s.charAt(i));
}
- return val;
+ return val.toString();
}
/**
@@ -315,11 +315,11 @@ public class ComCrypto {
public String normalizeForLDAP(String s) {
- String val = "";
+ StringBuffer val = new StringBuffer();
for (int i = 0; i < s.length(); i++) {
if ((s.charAt(i) == '\\') && (s.charAt(i + 1) == 'n')) {
- val += '\n' + " ";
+ val.append(System.getProperty("line.separator") + " ");
i++;
continue;
} else if ((s.charAt(i) == '\\') && (s.charAt(i + 1) == 'r')) {
@@ -328,9 +328,9 @@ public class ComCrypto {
} else if (s.charAt(i) == '"') {
continue;
}
- val += s.charAt(i);
+ val.append(s.charAt(i));
}
- return val;
+ return val.toString();
}
/**
@@ -339,20 +339,20 @@ public class ComCrypto {
public String pkcs7Convertcert(String s) {
- String val = "";
+ StringBuffer val = new StringBuffer();
int len = s.length();
for (int i = 0; i < len; i = i + 64) {
if (i + 64 < len) {
- val = val + s.substring(i, i + 64) + "\n";
+ val.append(s.substring(i, i + 64)+System.getProperty("line.separator"));
} else {
- val = val + s.substring(i, len);
+ val.append(s.substring(i, len));
}
}
- return val;
+ return val.toString();
}
/**
diff --git a/base/silent/src/com/netscape/pkisilent/common/ServerInfo.java b/base/silent/src/com/netscape/pkisilent/common/ServerInfo.java
index 7ff761720..706d4ccee 100644
--- a/base/silent/src/com/netscape/pkisilent/common/ServerInfo.java
+++ b/base/silent/src/com/netscape/pkisilent/common/ServerInfo.java
@@ -244,17 +244,17 @@ public class ServerInfo {
private String stripSpace(String s) {
- String val = "";
+ StringBuffer val = new StringBuffer();
for (int i = 0; i < s.length(); i++) {
if ((s.charAt(i) == ' ')) {
i++;
continue;
} else {
- val += s.charAt(i);
+ val.append(s.charAt(i));
}
}
- return val;
+ return val.toString();
}
private void readAdminConfig() {
diff --git a/base/silent/src/com/netscape/pkisilent/common/Utilities.java b/base/silent/src/com/netscape/pkisilent/common/Utilities.java
index 22a0c3fcf..08c96e194 100644
--- a/base/silent/src/com/netscape/pkisilent/common/Utilities.java
+++ b/base/silent/src/com/netscape/pkisilent/common/Utilities.java
@@ -113,7 +113,7 @@ public class Utilities {
return null;
}
- String val = "";
+ StringBuffer val = new StringBuffer();
for (int i = 0; i < s.length(); i++) {
if ((s.charAt(i) == '\\') && (s.charAt(i + 1) == 'n')) {
@@ -125,9 +125,9 @@ public class Utilities {
} else if (s.charAt(i) == '"') {
continue;
}
- val += s.charAt(i);
+ val.append(s.charAt(i));
}
- return val;
+ return val.toString();
}
@@ -137,11 +137,11 @@ public class Utilities {
return null;
}
- String val = "";
+ StringBuffer val = new StringBuffer();
for (int i = 0; i < s.length(); i++) {
if ((s.charAt(i) == '\\') && (s.charAt(i + 1) == 'n')) {
- val += '\n';
+ val.append(System.getProperty("line.separator"));
i++;
continue;
} else if ((s.charAt(i) == '\\') && (s.charAt(i + 1) == 'r')) {
@@ -150,9 +150,9 @@ public class Utilities {
} else if (s.charAt(i) == '"') {
continue;
}
- val += s.charAt(i);
+ val.append(s.charAt(i));
}
- return val;
+ return val.toString();
}
/*
@@ -262,7 +262,7 @@ public class Utilities {
* a binary array[] to a Ldap filter string
*/
public static String escapeBinaryData(byte data[]) {
- String result = "";
+ StringBuffer result = new StringBuffer();
for (int i = 0; i < data.length; i++) {
String s = Integer.toHexString(0xff & data[i]);
@@ -270,11 +270,11 @@ public class Utilities {
if (s.length() == 1) {
s = "0" + s;
}
- result = result + "\\" + s;
+ result.append("\\" + s);
}
- System.out.println("LDAP_FILTER=" + result);
- return result;
+ System.out.println("LDAP_FILTER=" + result.toString());
+ return result.toString();
}
/*
@@ -323,14 +323,14 @@ public class Utilities {
X500Name dname = (X500Name) csn1.get(CertificateSubjectName.DN_NAME);
- String pp = "";
+ StringBuffer pp = new StringBuffer();
RDN[] rdns = dname.getNames();
for (int i = rdns.length - 1; i >= 0; i--) {
- pp = pp + rdns[i] + "\n";
+ pp.append(rdns[i] + System.getProperty("line.separator"));
}
- cr.subject = pp;
+ cr.subject = pp.toString();
} catch (Exception e) {
System.out.println("ERROR: Exception when decoding certificate=" + e);
diff --git a/base/util/src/netscape/security/util/ObjectIdentifier.java b/base/util/src/netscape/security/util/ObjectIdentifier.java
index 99de73e0d..e8ac1b626 100644
--- a/base/util/src/netscape/security/util/ObjectIdentifier.java
+++ b/base/util/src/netscape/security/util/ObjectIdentifier.java
@@ -345,15 +345,16 @@ final public class ObjectIdentifier implements Serializable {
* will not be understood everywhere.
*/
public String toString() {
- String retval;
+ StringBuffer retval = new StringBuffer();
+
int i;
- for (i = 0, retval = ""; i < componentLen; i++) {
+ for (i = 0; i < componentLen; i++) {
if (i != 0)
- retval += ".";
- retval += components[i];
+ retval.append(".");
+ retval.append(components[i]);
}
- return retval;
+ return retval.toString();
}
/*
diff --git a/base/util/src/netscape/security/x509/Attribute.java b/base/util/src/netscape/security/x509/Attribute.java
index 6cc1bfa03..8c3fc1fbd 100644
--- a/base/util/src/netscape/security/x509/Attribute.java
+++ b/base/util/src/netscape/security/x509/Attribute.java
@@ -214,14 +214,15 @@ public final class Attribute implements Serializable, DerEncoder {
*/
public String toString() {
String theoid = "Attribute: " + oid + "\n";
- String values = "Values: ";
+ StringBuffer values = new StringBuffer();
+ values.append("Values: ");
Enumeration<String> n = valueSet.elements();
if (n.hasMoreElements()) {
- values += n.nextElement();
+ values.append(n.nextElement());
while (n.hasMoreElements())
- values += "," + n.nextElement();
+ values.append("," + n.nextElement());
}
- return theoid + values + "\n";
+ return theoid + values.toString() + "\n";
}
//========== PRIVATE METHODS ==================================
diff --git a/base/util/src/netscape/security/x509/CertificateChain.java b/base/util/src/netscape/security/x509/CertificateChain.java
index 346dcc740..1329217ac 100644
--- a/base/util/src/netscape/security/x509/CertificateChain.java
+++ b/base/util/src/netscape/security/x509/CertificateChain.java
@@ -123,13 +123,15 @@ public class CertificateChain implements Serializable {
* Converts the certificate chain to a readable string.
*/
public String toString() {
+
String s = "[\n";
if (mChain == null)
return "[empty]";
+ StringBuffer tempBuffer = new StringBuffer();
for (int i = 0; i < mChain.length; i++) {
- s += mChain[i].toString();
+ tempBuffer.append(mChain[i].toString());
}
- s += "]\n";
+ s += tempBuffer.toString() + "]\n";
return s;
}
diff --git a/base/util/src/netscape/security/x509/GeneralSubtrees.java b/base/util/src/netscape/security/x509/GeneralSubtrees.java
index 720b6b225..d24774ab4 100644
--- a/base/util/src/netscape/security/x509/GeneralSubtrees.java
+++ b/base/util/src/netscape/security/x509/GeneralSubtrees.java
@@ -75,15 +75,15 @@ public class GeneralSubtrees {
public String toPrint(int indent) {
- String s = "";
+ StringBuffer s = new StringBuffer();
GeneralSubtree element;
for (Enumeration<GeneralSubtree> e = trees.elements(); e.hasMoreElements();) {
element = e.nextElement();
- s = s + pp.indent(indent + 4) + element.toPrint(indent) + "\n";
+ s.append(pp.indent(indent + 4) + element.toPrint(indent) + System.getProperty("line.separator"));
}
- return (s);
+ return (s.toString());
}
/**
diff --git a/base/util/src/netscape/security/x509/IPAddressName.java b/base/util/src/netscape/security/x509/IPAddressName.java
index 1270f910d..4ff8b8a0c 100644
--- a/base/util/src/netscape/security/x509/IPAddressName.java
+++ b/base/util/src/netscape/security/x509/IPAddressName.java
@@ -142,24 +142,25 @@ public class IPAddressName implements GeneralNameInterface {
+ (address[1] & 0xff) + "."
+ (address[2] & 0xff) + "." + (address[3] & 0xff));
} else {
- String r = "IPAddress: " + Integer.toHexString(address[0] & 0xff);
+ StringBuffer r = new StringBuffer();
+ r.append("IPAddress: " + Integer.toHexString(address[0] & 0xff));
String hexString = Integer.toHexString(address[1] & 0xff);
if (hexString.length() == 1) {
- r = r + "0" + hexString;
+ r.append("0" + hexString);
} else {
- r += hexString;
+ r.append(hexString);
}
for (int i = 2; i < address.length;) {
- r += ":" + Integer.toHexString(address[i] & 0xff);
+ r.append(":" + Integer.toHexString(address[i] & 0xff));
hexString = Integer.toHexString(address[i + 1] & 0xff);
if (hexString.length() == 1) {
- r = r + "0" + hexString;
+ r.append("0" + hexString);
} else {
- r += hexString;
+ r.append(hexString);
}
i += 2;
}
- return r;
+ return r.toString();
}
}
}
diff --git a/base/util/src/netscape/security/x509/PolicyQualifiers.java b/base/util/src/netscape/security/x509/PolicyQualifiers.java
index 632dc89de..def90066e 100644
--- a/base/util/src/netscape/security/x509/PolicyQualifiers.java
+++ b/base/util/src/netscape/security/x509/PolicyQualifiers.java
@@ -78,14 +78,15 @@ public class PolicyQualifiers implements java.io.Serializable {
* Returns a printable representation of the CertificatePolicyId.
*/
public String toString() {
- String s = "PolicyQualifiers: [";
+ StringBuffer s = new StringBuffer();
+ s.append("PolicyQualifiers: [");
for (int i = 0; i < mInfo.size(); i++) {
PolicyQualifierInfo pq = mInfo.elementAt(i);
- s = s + pq.toString();
+ s.append(pq.toString());
}
- s = s + "]\n";
+ s.append("]\n");
- return (s);
+ return s.toString();
}
/**
diff --git a/base/util/src/netscape/security/x509/SubjectDirAttributesExtension.java b/base/util/src/netscape/security/x509/SubjectDirAttributesExtension.java
index 3414b81c6..42ef26aa9 100644
--- a/base/util/src/netscape/security/x509/SubjectDirAttributesExtension.java
+++ b/base/util/src/netscape/security/x509/SubjectDirAttributesExtension.java
@@ -197,14 +197,16 @@ public class SubjectDirAttributesExtension extends Extension
* Return user readable form of extension.
*/
public String toString() {
+
String s = super.toString() + "SubjectDirectoryAttributes:[\n";
Enumeration<Attribute> attrs = attrList.elements();
+ StringBuffer tempBuffer = new StringBuffer();
while (attrs.hasMoreElements()) {
Attribute attr = attrs.nextElement();
- s += attr.toString();
+ tempBuffer.append(attr.toString());
}
-
+ s += tempBuffer.toString();
return (s + "]\n");
}