>From 39ec9846797f10a288f6d675a1c6e06a1a1d0470 Mon Sep 17 00:00:00 2001
From: Abhishek Koneru <akoneru@redhat.com>
Date: Wed, 27 Jun 2012 14:27:55 -0400
Subject: [PATCH] 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   |    2 +-
 .../com/netscape/cmscore/authentication/VerifiedCerts.java   |    4 ++--
 .../com/netscape/cmscore/cert/CrossCertPairSubsystem.java    |    2 +-
 .../src/com/netscape/cmscore/cert/OidLoaderSubsystem.java    |    2 +-
 .../src/com/netscape/cmscore/cert/X500NameSubsystem.java     |    2 +-
 .../src/com/netscape/cmscore/dbs/CertificateRepository.java  |    3 ++-
 base/common/src/com/netscape/cmscore/dbs/DBVirtualList.java  |   10 ++++++----
 base/common/src/com/netscape/cmscore/dbs/KeyRepository.java  |    2 +-
 .../com/netscape/cmscore/ldapconn/LdapBoundConnFactory.java  |    2 +-
 .../com/netscape/cmscore/policy/GenericPolicyProcessor.java  |    2 +-
 .../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            |    2 +-
 16 files changed, 32 insertions(+), 28 deletions(-)

diff --git a/base/ca/src/com/netscape/ca/CRLIssuingPoint.java b/base/ca/src/com/netscape/ca/CRLIssuingPoint.java
index 46891fd6b2c425da40b9263906111b2b34db4543..c29bc326d7dd6cbea5180e1fae0e370708ac65e3 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<Long> getSplitTimes() {
+    public synchronized Vector<Long> getSplitTimes() {
         Vector<Long> splits = new Vector<Long>();
 
         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 f8f7588a7bef9fa27d1fc61ff45d22fc0053273a..aebb6bf6b500ac1a2bba699a88b05900603f3355 100644
--- a/base/common/src/com/netscape/certsrv/request/ARequestNotifier.java
+++ b/base/common/src/com/netscape/certsrv/request/ARequestNotifier.java
@@ -451,7 +451,7 @@ public class ARequestNotifier implements IRequestNotifier {
      *
      * @param id request request
      */
-    public void recoverPublishingQueue(String id) {
+    public synchronized void recoverPublishingQueue(String id) {
         CMS.debug("recoverPublishingQueue  mRequests.size()=" + mRequests.size() + "(" + mMaxRequests + ")" +
                       " requests by adding request " + id);
         if (mRequests.size() == 0) {
diff --git a/base/common/src/com/netscape/cmscore/authentication/VerifiedCerts.java b/base/common/src/com/netscape/cmscore/authentication/VerifiedCerts.java
index 01c455464c6ef0d7a287d30131afe8dce7fa41ca..ccefe5b219b5defcd3c5ae24f90fbe4f651427c5 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 dd7918bd561015ff360a7c498d04e30f61b1227f..577a41256641c24564b9dde03c768883bf157d6b 100644
--- a/base/common/src/com/netscape/cmscore/cert/CrossCertPairSubsystem.java
+++ b/base/common/src/com/netscape/cmscore/cert/CrossCertPairSubsystem.java
@@ -96,7 +96,7 @@ public class CrossCertPairSubsystem implements ICrossCertPairSubsystem {
         mId = id;
     }
 
-    public void init(ISubsystem owner, IConfigStore config)
+    public synchronized void init(ISubsystem owner, IConfigStore config)
             throws EBaseException {
         try {
             mConfig = config;
diff --git a/base/common/src/com/netscape/cmscore/cert/OidLoaderSubsystem.java b/base/common/src/com/netscape/cmscore/cert/OidLoaderSubsystem.java
index 0feebb7ec21dcec0036361cf6b7e892beb5ef344..95bbd98e7ffb1b9453166ebcf86618a9d040d241 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 96dc64e578e13c9ba993e8e8fa31a7df1538c1d5..7accf2b4f0bb63446d46fe8c95888b1cedbc685a 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 0872d1f4050551495adb54d2ee9af17a83d23d2e..b5ab354627ce23b12a16f55e505382ba169da935 100644
--- a/base/common/src/com/netscape/cmscore/dbs/CertificateRepository.java
+++ b/base/common/src/com/netscape/cmscore/dbs/CertificateRepository.java
@@ -226,7 +226,8 @@ public class CertificateRepository extends Repository
      * 0 - disable
      * >0 - enable
      */
-    public void setCertStatusUpdateInterval(IRepository requestRepository, int interval, boolean listenToCloneModifications) {
+    public synchronized void setCertStatusUpdateInterval(IRepository requestRepository, int interval,
+            boolean listenToCloneModifications) {
 
         CMS.debug("In setCertStatusUpdateInterval " + interval);
 
diff --git a/base/common/src/com/netscape/cmscore/dbs/DBVirtualList.java b/base/common/src/com/netscape/cmscore/dbs/DBVirtualList.java
index 854a92e15a44f9b5f5e148e8523c57d4a722d3b9..69aaef8907ca4a91605d3bbe5a03a25b55fb01cb 100644
--- a/base/common/src/com/netscape/cmscore/dbs/DBVirtualList.java
+++ b/base/common/src/com/netscape/cmscore/dbs/DBVirtualList.java
@@ -308,12 +308,14 @@ public class DBVirtualList<E> implements IDBVirtualList<E> {
         if (sortKeys == null)
             throw new EBaseException("sort keys cannot be null");
         try {
+            synchronized (mRegistry) {
+                mKeys = new LDAPSortKey[sortKeys.length];
 
-            mKeys = new LDAPSortKey[sortKeys.length];
-            String la[] = mRegistry.getLDAPAttributes(sortKeys);
+                String la[] = mRegistry.getLDAPAttributes(sortKeys);
 
-            for (int j = 0; j < sortKeys.length; j++) {
-                mKeys[j] = new LDAPSortKey(la[j]);
+                for (int j = 0; j < sortKeys.length; j++) {
+                    mKeys[j] = new LDAPSortKey(la[j]);
+                }
             }
         } catch (Exception e) {
 
diff --git a/base/common/src/com/netscape/cmscore/dbs/KeyRepository.java b/base/common/src/com/netscape/cmscore/dbs/KeyRepository.java
index 0fbff688a7608daa16d6c373047f1460bdafc537..51537b2cae4e6acd3158cc8ab69b517589dc5d5d 100644
--- a/base/common/src/com/netscape/cmscore/dbs/KeyRepository.java
+++ b/base/common/src/com/netscape/cmscore/dbs/KeyRepository.java
@@ -151,7 +151,7 @@ public class KeyRepository extends Repository implements IKeyRepository {
 
     }
 
-    public void setKeyStatusUpdateInterval(IRepository requestRepo, int interval) {
+    public synchronized void setKeyStatusUpdateInterval(IRepository requestRepo, int interval) {
 
         CMS.debug("In setKeyStatusUpdateInterval " + interval);
 
diff --git a/base/common/src/com/netscape/cmscore/ldapconn/LdapBoundConnFactory.java b/base/common/src/com/netscape/cmscore/ldapconn/LdapBoundConnFactory.java
index c3e84f13607f8dd2b8422c33f35bac39a9d84daa..5be645b56ed15ccf8fb5977169270faddce73967 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 d717d973220bef79d37f6d9c77d420f639e4e394..7b3eac27404318a3c1c65dda09c88f6a9a54662b 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 5822542a3805764171ae9bf379c15a7892cc4898..40499577e80fe065ebeede5d2925022c4eb670dd 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<Vector<String>> data = new Vector<Vector<String>>();
         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 2d53552a08070548fa8fac1f253afe3084b3279e..36f698fcf87eca10e28824298ba5545786069a2c 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 9b5cf7b5285d838fc5db4048b67b613e091ba703..5e7160e38e51d9137dcb28f510cb7ee7fb8f56ec 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 884304301d5b139b60cfbf972d03aeb742f0fc21..9ccb0fc1fd6e2360f36e615459292fa943ab7168 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<AclEntry> {
     }
 
     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 e64873942c9cd4fb4406d3779bd0d7bd434450ad..98405e51e6d3bce82805daba0843389f787667db 100644
--- a/base/util/src/netscape/security/provider/MD5.java
+++ b/base/util/src/netscape/security/provider/MD5.java
@@ -227,7 +227,7 @@ public final class MD5 extends MessageDigestSpi implements Cloneable {
      * to 0. Given this implementation you are constrained to counting
      * 2^64 bits.
      */
-    public void init() {
+    public synchronized void init() {
         state = new int[4];
         transformBuffer = new int[16];
         buffer = new byte[64];
-- 
1.7.10.2

