From 10502e34a10fb3b672aef1161cc271003c7806ba Mon Sep 17 00:00:00 2001 From: Abhishek Koneru Date: Wed, 27 Jun 2012 14:27:55 -0400 Subject: Fixes for Guarded_By_Violation issues shown in Coverity --- base/ca/src/com/netscape/ca/CRLIssuingPoint.java | 9 ++++----- .../src/com/netscape/certsrv/request/ARequestNotifier.java | 4 +++- .../src/com/netscape/cmscore/authentication/VerifiedCerts.java | 4 ++-- .../src/com/netscape/cmscore/cert/CrossCertPairSubsystem.java | 6 ++++-- .../common/src/com/netscape/cmscore/cert/OidLoaderSubsystem.java | 2 +- base/common/src/com/netscape/cmscore/cert/X500NameSubsystem.java | 2 +- .../src/com/netscape/cmscore/dbs/CertificateRepository.java | 8 +++++--- base/common/src/com/netscape/cmscore/dbs/DBVirtualList.java | 6 ++++-- base/common/src/com/netscape/cmscore/dbs/KeyRepository.java | 5 +++-- .../src/com/netscape/cmscore/ldapconn/LdapBoundConnFactory.java | 2 +- .../src/com/netscape/cmscore/policy/GenericPolicyProcessor.java | 2 +- base/common/src/com/netscape/cmscore/util/ProfileSubsystem.java | 4 ++-- base/kra/src/com/netscape/kra/TokenKeyRecoveryService.java | 2 +- base/silent/src/com/netscape/pkisilent/common/ComCrypto.java | 4 ++-- base/util/src/netscape/security/acl/AclImpl.java | 8 +++++--- base/util/src/netscape/security/provider/MD5.java | 4 +++- 16 files changed, 42 insertions(+), 30 deletions(-) diff --git a/base/ca/src/com/netscape/ca/CRLIssuingPoint.java b/base/ca/src/com/netscape/ca/CRLIssuingPoint.java index 46891fd6b..c29bc326d 100644 --- a/base/ca/src/com/netscape/ca/CRLIssuingPoint.java +++ b/base/ca/src/com/netscape/ca/CRLIssuingPoint.java @@ -1297,7 +1297,7 @@ public class CRLIssuingPoint implements ICRLIssuingPoint, Runnable { return mSigningAlgorithm; } - public String getLastSigningAlgorithm() { + public synchronized String getLastSigningAlgorithm() { return mLastSigningAlgorithm; } @@ -1773,7 +1773,6 @@ public class CRLIssuingPoint implements ICRLIssuingPoint, Runnable { } } } catch (EBaseException e1) { - // TODO Auto-generated catch block e1.printStackTrace(); } mUpdateThread = null; @@ -2307,7 +2306,7 @@ public class CRLIssuingPoint implements ICRLIssuingPoint, Runnable { return revocationDate; } - public Vector getSplitTimes() { + public synchronized Vector getSplitTimes() { Vector splits = new Vector(); for (int i = 0; i < mSplits.length; i++) { @@ -2316,7 +2315,7 @@ public class CRLIssuingPoint implements ICRLIssuingPoint, Runnable { return splits; } - public int isCRLUpdateInProgress() { + public synchronized int isCRLUpdateInProgress() { return mUpdatingCRL; } @@ -2884,7 +2883,7 @@ public class CRLIssuingPoint implements ICRLIssuingPoint, Runnable { } } - protected void log(int level, String msg) { + protected synchronized void log(int level, String msg) { mLogger.log(ILogger.EV_SYSTEM, null, ILogger.S_CA, level, "CRLIssuingPoint " + mId + " - " + msg); } diff --git a/base/common/src/com/netscape/certsrv/request/ARequestNotifier.java b/base/common/src/com/netscape/certsrv/request/ARequestNotifier.java index f8f7588a7..4a6e3260b 100644 --- a/base/common/src/com/netscape/certsrv/request/ARequestNotifier.java +++ b/base/common/src/com/netscape/certsrv/request/ARequestNotifier.java @@ -459,7 +459,9 @@ public class ARequestNotifier implements IRequestNotifier { CMS.debug("recoverPublishingQueue extended buffer to " + mRequests.size() + "(" + mMaxRequests + ")" + " requests by adding request " + id); if (morePublishingThreads()) { - mSearchForRequests = true; + synchronized (this) { + mSearchForRequests = true; + } try { Thread notifierThread = new Thread(new RunListeners(this)); if (notifierThread != null) { diff --git a/base/common/src/com/netscape/cmscore/authentication/VerifiedCerts.java b/base/common/src/com/netscape/cmscore/authentication/VerifiedCerts.java index 01c455464..ccefe5b21 100644 --- a/base/common/src/com/netscape/cmscore/authentication/VerifiedCerts.java +++ b/base/common/src/com/netscape/cmscore/authentication/VerifiedCerts.java @@ -53,7 +53,7 @@ public class VerifiedCerts { mUnknownStateInterval = unknownStateInterval; } - public void update(X509CertImpl cert, int status) { + public synchronized void update(X509CertImpl cert, int status) { if (cert != null) { byte[] certEncoded = null; @@ -90,7 +90,7 @@ public class VerifiedCerts { } } - public int check(X509CertImpl cert) { + public synchronized int check(X509CertImpl cert) { int status = VerifiedCert.UNKNOWN; if (mLast != mNext && mInterval > 0) { // if not empty and diff --git a/base/common/src/com/netscape/cmscore/cert/CrossCertPairSubsystem.java b/base/common/src/com/netscape/cmscore/cert/CrossCertPairSubsystem.java index dd7918bd5..4db850d2e 100644 --- a/base/common/src/com/netscape/cmscore/cert/CrossCertPairSubsystem.java +++ b/base/common/src/com/netscape/cmscore/cert/CrossCertPairSubsystem.java @@ -101,8 +101,10 @@ public class CrossCertPairSubsystem implements ICrossCertPairSubsystem { try { mConfig = config; mLogger = CMS.getLogger(); - mCa = (ICertificateAuthority) CMS.getSubsystem("ca"); - mPublisherProcessor = mCa.getPublisherProcessor(); + synchronized (this) { + mCa = (ICertificateAuthority) CMS.getSubsystem("ca"); + mPublisherProcessor = mCa.getPublisherProcessor(); + } // initialize LDAP connection factory IConfigStore ldapConfig = mConfig.getSubStore(PROP_LDAP); diff --git a/base/common/src/com/netscape/cmscore/cert/OidLoaderSubsystem.java b/base/common/src/com/netscape/cmscore/cert/OidLoaderSubsystem.java index 0feebb7ec..95bbd98e7 100644 --- a/base/common/src/com/netscape/cmscore/cert/OidLoaderSubsystem.java +++ b/base/common/src/com/netscape/cmscore/cert/OidLoaderSubsystem.java @@ -182,7 +182,7 @@ public class OidLoaderSubsystem implements ISubsystem { * * @return configuration store of this subsystem */ - public IConfigStore getConfigStore() { + public synchronized IConfigStore getConfigStore() { return mConfig; } diff --git a/base/common/src/com/netscape/cmscore/cert/X500NameSubsystem.java b/base/common/src/com/netscape/cmscore/cert/X500NameSubsystem.java index 96dc64e57..7accf2b4f 100644 --- a/base/common/src/com/netscape/cmscore/cert/X500NameSubsystem.java +++ b/base/common/src/com/netscape/cmscore/cert/X500NameSubsystem.java @@ -277,7 +277,7 @@ public class X500NameSubsystem implements ISubsystem { protected ILogger mLogger = null; - protected void log(int level, String msg) { + protected synchronized void log(int level, String msg) { mLogger.log(ILogger.EV_SYSTEM, ILogger.S_ADMIN, level, msg); } diff --git a/base/common/src/com/netscape/cmscore/dbs/CertificateRepository.java b/base/common/src/com/netscape/cmscore/dbs/CertificateRepository.java index 0872d1f40..14e06aeb3 100644 --- a/base/common/src/com/netscape/cmscore/dbs/CertificateRepository.java +++ b/base/common/src/com/netscape/cmscore/dbs/CertificateRepository.java @@ -226,11 +226,13 @@ public class CertificateRepository extends Repository * 0 - disable * >0 - enable */ - public void setCertStatusUpdateInterval(IRepository requestRepository, int interval, boolean listenToCloneModifications) { + public void setCertStatusUpdateInterval(IRepository requestRepository, int interval, + boolean listenToCloneModifications) { CMS.debug("In setCertStatusUpdateInterval " + interval); - - this.requestRepository = requestRepository; + synchronized (this) { + this.requestRepository = requestRepository; + } // stop running tasks if (certStatusUpdateTask != null) { diff --git a/base/common/src/com/netscape/cmscore/dbs/DBVirtualList.java b/base/common/src/com/netscape/cmscore/dbs/DBVirtualList.java index 854a92e15..51a9230ac 100644 --- a/base/common/src/com/netscape/cmscore/dbs/DBVirtualList.java +++ b/base/common/src/com/netscape/cmscore/dbs/DBVirtualList.java @@ -308,9 +308,11 @@ public class DBVirtualList implements IDBVirtualList { if (sortKeys == null) throw new EBaseException("sort keys cannot be null"); try { - mKeys = new LDAPSortKey[sortKeys.length]; - String la[] = mRegistry.getLDAPAttributes(sortKeys); + String la[] = null; + synchronized (this) { + la = mRegistry.getLDAPAttributes(sortKeys); + } for (int j = 0; j < sortKeys.length; j++) { mKeys[j] = new LDAPSortKey(la[j]); diff --git a/base/common/src/com/netscape/cmscore/dbs/KeyRepository.java b/base/common/src/com/netscape/cmscore/dbs/KeyRepository.java index 0fbff688a..fb3b9b24a 100644 --- a/base/common/src/com/netscape/cmscore/dbs/KeyRepository.java +++ b/base/common/src/com/netscape/cmscore/dbs/KeyRepository.java @@ -154,8 +154,9 @@ public class KeyRepository extends Repository implements IKeyRepository { public void setKeyStatusUpdateInterval(IRepository requestRepo, int interval) { CMS.debug("In setKeyStatusUpdateInterval " + interval); - - this.requestRepository = requestRepo; + synchronized (this) { + this.requestRepository = requestRepo; + } // stop running task if (mKeyStatusUpdateTask != null) { diff --git a/base/common/src/com/netscape/cmscore/ldapconn/LdapBoundConnFactory.java b/base/common/src/com/netscape/cmscore/ldapconn/LdapBoundConnFactory.java index c3e84f136..5be645b56 100644 --- a/base/common/src/com/netscape/cmscore/ldapconn/LdapBoundConnFactory.java +++ b/base/common/src/com/netscape/cmscore/ldapconn/LdapBoundConnFactory.java @@ -82,7 +82,7 @@ public class LdapBoundConnFactory implements ILdapBoundConnFactory { return mTotal; } - public int freeConn() { + public synchronized int freeConn() { return mNumConns; } diff --git a/base/common/src/com/netscape/cmscore/policy/GenericPolicyProcessor.java b/base/common/src/com/netscape/cmscore/policy/GenericPolicyProcessor.java index d717d9732..7b3eac274 100644 --- a/base/common/src/com/netscape/cmscore/policy/GenericPolicyProcessor.java +++ b/base/common/src/com/netscape/cmscore/policy/GenericPolicyProcessor.java @@ -129,7 +129,7 @@ public class GenericPolicyProcessor implements IPolicyProcessor { * * @return configuration store */ - public IConfigStore getConfigStore() { + public synchronized IConfigStore getConfigStore() { return mConfig; } diff --git a/base/common/src/com/netscape/cmscore/util/ProfileSubsystem.java b/base/common/src/com/netscape/cmscore/util/ProfileSubsystem.java index 5822542a3..40499577e 100644 --- a/base/common/src/com/netscape/cmscore/util/ProfileSubsystem.java +++ b/base/common/src/com/netscape/cmscore/util/ProfileSubsystem.java @@ -144,7 +144,7 @@ public class ProfileSubsystem extends Frame implements ISubsystem, Runnable { return null; } - public void updateGeneralPanel() { + public synchronized void updateGeneralPanel() { Runtime.getRuntime().gc(); String text = "JDK VM Information " + "\n" + @@ -161,7 +161,7 @@ public class ProfileSubsystem extends Frame implements ISubsystem, Runnable { mTextArea.setText(text); } - public void updateThreadPanel() { + public synchronized void updateThreadPanel() { Thread currentThread = Thread.currentThread(); Vector> data = new Vector>(); Thread threads[] = new Thread[100]; diff --git a/base/kra/src/com/netscape/kra/TokenKeyRecoveryService.java b/base/kra/src/com/netscape/kra/TokenKeyRecoveryService.java index 2d53552a0..36f698fcf 100644 --- a/base/kra/src/com/netscape/kra/TokenKeyRecoveryService.java +++ b/base/kra/src/com/netscape/kra/TokenKeyRecoveryService.java @@ -194,7 +194,7 @@ public class TokenKeyRecoveryService implements IService { * @return operation success or not * @exception EBaseException failed to serve */ - public boolean serviceRequest(IRequest request) throws EBaseException { + public synchronized boolean serviceRequest(IRequest request) throws EBaseException { String auditMessage = null; String auditSubjectID = null; String auditRecoveryID = ILogger.UNIDENTIFIED; diff --git a/base/silent/src/com/netscape/pkisilent/common/ComCrypto.java b/base/silent/src/com/netscape/pkisilent/common/ComCrypto.java index 48b364349..7abe775a3 100644 --- a/base/silent/src/com/netscape/pkisilent/common/ComCrypto.java +++ b/base/silent/src/com/netscape/pkisilent/common/ComCrypto.java @@ -141,7 +141,7 @@ public class ComCrypto { certpackage = cd; } - public void setGenerateRequest(boolean c) { + public synchronized void setGenerateRequest(boolean c) { generaterequest = c; } @@ -167,7 +167,7 @@ public class ComCrypto { dualkey = dkey; } - public String getPkcs10Request() { + public synchronized String getPkcs10Request() { return pkcs10request; } diff --git a/base/util/src/netscape/security/acl/AclImpl.java b/base/util/src/netscape/security/acl/AclImpl.java index 884304301..9ccb0fc1f 100644 --- a/base/util/src/netscape/security/acl/AclImpl.java +++ b/base/util/src/netscape/security/acl/AclImpl.java @@ -370,9 +370,11 @@ final class AclEnumerator implements Enumeration { } public boolean hasMoreElements() { - return (u1.hasMoreElements() || - u2.hasMoreElements() || - g1.hasMoreElements() || g2.hasMoreElements()); + synchronized (acl) { + return (u1.hasMoreElements() || + u2.hasMoreElements() || + g1.hasMoreElements() || g2.hasMoreElements()); + } } public AclEntry nextElement() { diff --git a/base/util/src/netscape/security/provider/MD5.java b/base/util/src/netscape/security/provider/MD5.java index e64873942..85f9da12d 100644 --- a/base/util/src/netscape/security/provider/MD5.java +++ b/base/util/src/netscape/security/provider/MD5.java @@ -230,7 +230,9 @@ public final class MD5 extends MessageDigestSpi implements Cloneable { public void init() { state = new int[4]; transformBuffer = new int[16]; - buffer = new byte[64]; + synchronized (this) { + buffer = new byte[64]; + } digestBits = new byte[16]; count = 0; // Load magic initialization constants. -- cgit