ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mad...@apache.org
Subject incubator-ranger git commit: First round of Coverity uncovered issues.
Date Wed, 25 Mar 2015 00:46:50 GMT
Repository: incubator-ranger
Updated Branches:
  refs/heads/master 59304ba8d -> cb4eb54b6


First round of Coverity uncovered issues.

Signed-off-by: Madhan Neethiraj <madhan@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/incubator-ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ranger/commit/cb4eb54b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/cb4eb54b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/cb4eb54b

Branch: refs/heads/master
Commit: cb4eb54b68b0bf54497a572cc81a4e17a72363b7
Parents: 59304ba
Author: Abhay Kulkarni <akulkarni@hortonworks.com>
Authored: Tue Mar 24 14:39:07 2015 -0700
Committer: Madhan Neethiraj <madhan@apache.org>
Committed: Tue Mar 24 17:12:58 2015 -0700

----------------------------------------------------------------------
 .../hadoop/config/RangerConfiguration.java      | 13 +++++----
 .../ranger/plugin/util/RangerRESTClient.java    | 13 +++++----
 .../hadoop/utils/RangerCredentialProvider.java  | 13 +++++----
 .../ranger/authorization/hbase/Crypt.java       | 13 +++++----
 .../agent/HadoopAuthClassTransformer.java       | 24 ++++++++--------
 .../ranger/services/hive/client/HiveClient.java | 29 ++++++++++++--------
 .../main/java/org/apache/util/sql/Jisql.java    | 10 +++++++
 .../service/filter/RangerRESTAPIFilter.java     |  7 ++---
 .../config/UserGroupSyncConfig.java             | 13 +++++----
 9 files changed, 78 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/cb4eb54b/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerConfiguration.java
----------------------------------------------------------------------
diff --git a/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerConfiguration.java
b/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerConfiguration.java
index 7c81d09..3610e9f 100644
--- a/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerConfiguration.java
+++ b/agents-common/src/main/java/org/apache/ranger/authorization/hadoop/config/RangerConfiguration.java
@@ -33,7 +33,7 @@ public class RangerConfiguration extends Configuration {
 	
 	private static final Logger LOG = Logger.getLogger(RangerConfiguration.class) ;
 	
-	private static RangerConfiguration config = null;
+	private static volatile RangerConfiguration config = null;
 	
 	private RangerConfiguration() {
 		super(false) ;
@@ -88,15 +88,16 @@ public class RangerConfiguration extends Configuration {
 	
 
 	public static RangerConfiguration getInstance() {
-		if (config == null) {
+        RangerConfiguration result = config;
+		if (result == null) {
 			synchronized (RangerConfiguration.class) {
-				RangerConfiguration temp = config;
-				if (temp == null) {
-					config = new RangerConfiguration();
+				result = config;
+				if (result == null) {
+					config = result = new RangerConfiguration();
 				}
 			}
 		}
-		return config;
+		return result;
 	}
 
 	public void initAudit(String appType) {

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/cb4eb54b/agents-common/src/main/java/org/apache/ranger/plugin/util/RangerRESTClient.java
----------------------------------------------------------------------
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/util/RangerRESTClient.java
b/agents-common/src/main/java/org/apache/ranger/plugin/util/RangerRESTClient.java
index f9cc570..1d57935 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/util/RangerRESTClient.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/util/RangerRESTClient.java
@@ -100,7 +100,7 @@ public class RangerRESTClient {
 	private String mTrustStoreType  = null;
 
 	private Gson   gsonBuilder = null;
-	private Client client      = null;
+	private volatile Client client      = null;
 
 	public RangerRESTClient() {
 		this(RangerConfiguration.getInstance().get(RANGER_PROP_POLICYMGR_URL),
@@ -150,15 +150,18 @@ public class RangerRESTClient {
 	}
 
 	public Client getClient() {
-		if(client == null) {
+        // result saves on access time when client is built at the time of the call
+        Client result = client;
+		if(result == null) {
 			synchronized(this) {
-				if(client == null) {
-					client = buildClient();
+                result = client;
+				if(result == null) {
+					client = result = buildClient();
 				}
 			}
 		}
 
-		return client;
+		return result;
 	}
 
 	private Client buildClient() {

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/cb4eb54b/agents-cred/src/main/java/org/apache/ranger/authorization/hadoop/utils/RangerCredentialProvider.java
----------------------------------------------------------------------
diff --git a/agents-cred/src/main/java/org/apache/ranger/authorization/hadoop/utils/RangerCredentialProvider.java
b/agents-cred/src/main/java/org/apache/ranger/authorization/hadoop/utils/RangerCredentialProvider.java
index ebfcc45..48d933b 100644
--- a/agents-cred/src/main/java/org/apache/ranger/authorization/hadoop/utils/RangerCredentialProvider.java
+++ b/agents-cred/src/main/java/org/apache/ranger/authorization/hadoop/utils/RangerCredentialProvider.java
@@ -34,19 +34,20 @@ public class RangerCredentialProvider {
 
   private static Log LOG = LogFactory.getLog(RangerCredentialProvider.class);
 
-  private static RangerCredentialProvider  me = null;
+  private static volatile RangerCredentialProvider  me = null;
 
   
   public static RangerCredentialProvider getInstance()  {
-	  if ( me == null) {
+      RangerCredentialProvider result = me;
+	  if ( result == null) {
 		  synchronized(RangerCredentialProvider.class) {
-			  RangerCredentialProvider temp = me;
-			  if ( temp == null){
-				  me = new RangerCredentialProvider();
+			  result = me;
+			  if ( result == null){
+				  me = result = new RangerCredentialProvider();
 			  }
 		  }
 	  }
-	return me;
+	return result;
   }
   
   public char[] getCredentialString(String url, String alias)  {

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/cb4eb54b/hbase-agent/src/main/java/org/apache/ranger/authorization/hbase/Crypt.java
----------------------------------------------------------------------
diff --git a/hbase-agent/src/main/java/org/apache/ranger/authorization/hbase/Crypt.java b/hbase-agent/src/main/java/org/apache/ranger/authorization/hbase/Crypt.java
index 272b0a0..1a32533 100644
--- a/hbase-agent/src/main/java/org/apache/ranger/authorization/hbase/Crypt.java
+++ b/hbase-agent/src/main/java/org/apache/ranger/authorization/hbase/Crypt.java
@@ -36,22 +36,23 @@ public class Crypt {
 	private static final String CIPHER_ALGO = "AES/CBC/PKCS5Padding";
 	private static final String CIPHER_INIT_ALGO = "AES";
 	
-	private static Crypt me = null ;
+	private static volatile Crypt me = null ;
 	
 	private Cipher encrypter = null;
 	private Cipher descrypter = null;
 
 
 	public static Crypt getInstance() {
-		if (me == null) {
+        Crypt result = me;
+		if (result == null) {
 			synchronized (Crypt.class) {
-				Crypt other = me ;
-				if (other == null) {
-					me = new Crypt() ;
+				result = me ;
+				if (result == null) {
+					me = result = new Crypt() ;
 				}
 			}
 		}
-		return me ;
+		return result ;
 	}
 	
 	private Crypt() {

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/cb4eb54b/hdfs-agent/src/main/java/org/apache/ranger/authorization/hadoop/agent/HadoopAuthClassTransformer.java
----------------------------------------------------------------------
diff --git a/hdfs-agent/src/main/java/org/apache/ranger/authorization/hadoop/agent/HadoopAuthClassTransformer.java
b/hdfs-agent/src/main/java/org/apache/ranger/authorization/hadoop/agent/HadoopAuthClassTransformer.java
index 742cf05..2b7a63e 100644
--- a/hdfs-agent/src/main/java/org/apache/ranger/authorization/hadoop/agent/HadoopAuthClassTransformer.java
+++ b/hdfs-agent/src/main/java/org/apache/ranger/authorization/hadoop/agent/HadoopAuthClassTransformer.java
@@ -37,23 +37,23 @@ public class HadoopAuthClassTransformer implements ClassFileTransformer
{
 		byte[] ret = aClassFileBuffer;
 
 		if (aClassName.equals("org/apache/hadoop/hdfs/server/namenode/FSPermissionChecker")) {
-			if (transformedClassByteCode == null) {
+            byte[] result = transformedClassByteCode;
+            if (result == null) {
+
 				byte[] injectedClassCode = injectFSPermissionCheckerHooks(aClassLoader, aClassName, aClassBeingRedefined,
aProtectionDomain, aClassFileBuffer);
 
 				if(injectedClassCode != null) {
-					if(transformedClassByteCode == null) {
-						synchronized(HadoopAuthClassTransformer.class) {
-							byte[] temp = transformedClassByteCode;
-							if (temp == null) {
-								transformedClassByteCode = injectedClassCode;
-							}
-						}
-					}
-				}
+                    synchronized (HadoopAuthClassTransformer.class) {
+                        result = transformedClassByteCode;
+                        if (result == null) {
+                            transformedClassByteCode = result = injectedClassCode;
+                        }
+                    }
+                }
 			}
 
-			if(transformedClassByteCode != null) {
-				ret = transformedClassByteCode;
+			if(result != null) {
+				ret = result;
 			}
 		}
 

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/cb4eb54b/hive-agent/src/main/java/org/apache/ranger/services/hive/client/HiveClient.java
----------------------------------------------------------------------
diff --git a/hive-agent/src/main/java/org/apache/ranger/services/hive/client/HiveClient.java
b/hive-agent/src/main/java/org/apache/ranger/services/hive/client/HiveClient.java
index 40efe2e..15ee2fc 100644
--- a/hive-agent/src/main/java/org/apache/ranger/services/hive/client/HiveClient.java
+++ b/hive-agent/src/main/java/org/apache/ranger/services/hive/client/HiveClient.java
@@ -189,21 +189,29 @@ public class HiveClient extends BaseClient implements Closeable {
 						}
 						finally {
 							close(stat) ;
+                            stat = null;
 						}
 						
 						sql = "show tables " ;
 						if (tableNameMatching != null && ! tableNameMatching.isEmpty()) {
 							sql = sql + " like \"" + tableNameMatching  + "\"" ;
 						}
-						stat =  con.createStatement()  ;
-						rs = stat.executeQuery(sql) ;
-						while (rs.next()) {
-							String tblName = rs.getString(1);
-							if ( tblList != null && tblList.contains(tblName)) {
-								continue;
-							}
-							ret.add(tblName);
-						}
+                        try {
+                            stat = con.createStatement();
+                            rs = stat.executeQuery(sql);
+                            while (rs.next()) {
+                                String tblName = rs.getString(1);
+                                if (tblList != null && tblList.contains(tblName))
{
+                                    continue;
+                                }
+                                ret.add(tblName);
+                            }
+                        } finally {
+                            close(rs);
+                            close(stat);
+                            rs = null;
+                            stat = null;
+                        }
 					 }
 				}
 			} catch (SQLTimeoutException sqlt) {
@@ -227,9 +235,6 @@ public class HiveClient extends BaseClient implements Closeable {
 					LOG.debug("<== HiveClient.getTblList() Error : " + sqle) ;
 				}
 				throw hdpException;
-			} finally {
-				close(rs) ;
-				close(stat) ;
 			}
 			
 		}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/cb4eb54b/jisql/src/main/java/org/apache/util/sql/Jisql.java
----------------------------------------------------------------------
diff --git a/jisql/src/main/java/org/apache/util/sql/Jisql.java b/jisql/src/main/java/org/apache/util/sql/Jisql.java
index e5dac9b..62da3c1 100644
--- a/jisql/src/main/java/org/apache/util/sql/Jisql.java
+++ b/jisql/src/main/java/org/apache/util/sql/Jisql.java
@@ -507,6 +507,16 @@ public class Jisql {
         			// Ignore IOE when closing streams
         		}
         	}
+            if (statement != null) {
+                try {
+                    if (!statement.isClosed()) {
+                        statement.close();
+                    }
+
+                } catch (SQLException sqle) {
+                    // Ignore
+                }
+            }
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/cb4eb54b/security-admin/src/main/java/org/apache/ranger/service/filter/RangerRESTAPIFilter.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/service/filter/RangerRESTAPIFilter.java
b/security-admin/src/main/java/org/apache/ranger/service/filter/RangerRESTAPIFilter.java
index 6087d35..21536ac 100644
--- a/security-admin/src/main/java/org/apache/ranger/service/filter/RangerRESTAPIFilter.java
+++ b/security-admin/src/main/java/org/apache/ranger/service/filter/RangerRESTAPIFilter.java
@@ -45,26 +45,25 @@ import com.sun.jersey.spi.container.ContainerResponse;
 
 public class RangerRESTAPIFilter extends LoggingFilter {
 	Logger logger = Logger.getLogger(RangerRESTAPIFilter.class);
-	static boolean initDone = false;
+	static volatile boolean initDone = false;
 
 	boolean logStdOut = true;
 	HashMap<String, String> regexPathMap = new HashMap<String, String>();
 	HashMap<String, Pattern> regexPatternMap = new HashMap<String, Pattern>();
 	List<String> regexList = new ArrayList<String>();
 	List<String> loggedRestPathErrors = new ArrayList<String>();
-	private final Object lock = new Object();
 
 	void init() {
 		if (initDone) {
 			return;
 		}
-		synchronized (lock) {
+		synchronized (RangerRESTAPIFilter.class) {
 			if (initDone) {
 				return;
 			}
 
 			logStdOut = PropertiesUtil.getBooleanProperty(
-					"xa.restapi.log.enabled", initDone);
+					"xa.restapi.log.enabled", false);
 
 			// Build hash map
 			try {

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/cb4eb54b/ugsync/src/main/java/org/apache/ranger/unixusersync/config/UserGroupSyncConfig.java
----------------------------------------------------------------------
diff --git a/ugsync/src/main/java/org/apache/ranger/unixusersync/config/UserGroupSyncConfig.java
b/ugsync/src/main/java/org/apache/ranger/unixusersync/config/UserGroupSyncConfig.java
index b2c2eb5..204a39c 100644
--- a/ugsync/src/main/java/org/apache/ranger/unixusersync/config/UserGroupSyncConfig.java
+++ b/ugsync/src/main/java/org/apache/ranger/unixusersync/config/UserGroupSyncConfig.java
@@ -146,18 +146,19 @@ public class UserGroupSyncConfig  {
 
 	private Properties prop = new Properties() ;
 	
-	private static UserGroupSyncConfig me = null ;
+	private static volatile UserGroupSyncConfig me = null ;
 	
 	public static UserGroupSyncConfig getInstance() {
-		if (me == null) {
+        UserGroupSyncConfig result = me;
+		if (result == null) {
 			synchronized(UserGroupSyncConfig.class) {
-				UserGroupSyncConfig temp = me ;
-				if (temp == null) {
-					me = new UserGroupSyncConfig() ;
+				result = me ;
+				if (result == null) {
+					me = result = new UserGroupSyncConfig() ;
 				}
 			}
 		}
-		return me ;
+		return result ;
 	}
 	
 	


Mime
View raw message