Skip to content

Commit 87a3813

Browse files
committed
Fixes unrestricted JNDI lookup in JDBC_PING datasource setup by checking datasource_jndi_name before fetching context
1 parent 2356481 commit 87a3813

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/org/jgroups/protocols/JDBC_PING.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ protected void closeConnection(final Connection connection) {
431431
protected DataSource getDataSourceFromJNDI(String name) {
432432
final DataSource data_source;
433433
InitialContext ctx = null;
434+
validateDatasourceJndiName(name);
434435
try {
435436
ctx = new InitialContext();
436437
Object whatever = ctx.lookup(name);
@@ -454,6 +455,16 @@ protected DataSource getDataSourceFromJNDI(String name) {
454455
}
455456
}
456457

458+
protected static void validateDatasourceJndiName(String name) {
459+
if(name == null || name.isEmpty())
460+
throw new IllegalArgumentException("JNDI name must not be empty");
461+
int colon=name.indexOf(':');
462+
if(colon > 0 && !name.regionMatches(true, 0, "java:", 0, "java:".length())) {
463+
NamingException cause=new NamingException("Remote JNDI URL schemes are not supported for datasource_jndi_name");
464+
throw new IllegalArgumentException("Remote JNDI URL schemes are not supported for datasource_jndi_name: " + name, cause);
465+
}
466+
}
467+
457468
protected void verifyConfigurationParameters() {
458469
// initialize_sql is skipped as the table could be created external to JDBC_PING
459470
assertNonNull("insert_single_sql", insert_single_sql,

0 commit comments

Comments
 (0)