This is an automated email from the ASF dual-hosted git repository.
remm pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push:
new 9935798c64 Fix possible NPE
9935798c64 is described below
commit 9935798c6494da0bb87ae8b835e094362ca14671
Author: remm <[email protected]>
AuthorDate: Mon Sep 11 11:31:27 2023 +0200
Fix possible NPE
Found by coverity.
---
java/org/apache/catalina/realm/DataSourceRealm.java | 9 ++++++++-
java/org/apache/catalina/realm/LocalStrings.properties | 1 +
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/java/org/apache/catalina/realm/DataSourceRealm.java
b/java/org/apache/catalina/realm/DataSourceRealm.java
index 1bfbbaef95..a27129a5da 100644
--- a/java/org/apache/catalina/realm/DataSourceRealm.java
+++ b/java/org/apache/catalina/realm/DataSourceRealm.java
@@ -28,6 +28,7 @@ import javax.naming.Context;
import javax.sql.DataSource;
import org.apache.catalina.LifecycleException;
+import org.apache.catalina.Server;
import org.apache.naming.ContextBindings;
/**
@@ -375,7 +376,13 @@ public class DataSourceRealm extends RealmBase {
context = ContextBindings.getClassLoader();
context = (Context) context.lookup("comp/env");
} else {
- context = getServer().getGlobalNamingContext();
+ Server server = getServer();
+ if (server == null) {
+ connectionSuccess = false;
+
containerLog.error(sm.getString("dataSourceRealm.noNamingContext"));
+ return null;
+ }
+ context = server.getGlobalNamingContext();
}
DataSource dataSource = (DataSource)
context.lookup(dataSourceName);
Connection connection = dataSource.getConnection();
diff --git a/java/org/apache/catalina/realm/LocalStrings.properties
b/java/org/apache/catalina/realm/LocalStrings.properties
index b13595272a..0fe5c0cf41 100644
--- a/java/org/apache/catalina/realm/LocalStrings.properties
+++ b/java/org/apache/catalina/realm/LocalStrings.properties
@@ -32,6 +32,7 @@ dataSourceRealm.commit=Exception committing connection before
closing
dataSourceRealm.exception=Exception performing authentication
dataSourceRealm.getPassword.exception=Exception retrieving password for [{0}]
dataSourceRealm.getRoles.exception=Exception retrieving roles for [{0}]
+dataSourceRealm.noNamingContext=Cannot access the server to retrieve the
naming context
jaasCallback.username=Returned username [{0}]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]