Skip to content

Commit b24aa46

Browse files
committed
Check URL scheme
1 parent 4a2e677 commit b24aa46

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

h2/src/main/org/h2/util/JdbcUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,9 @@ public static Connection getConnection(String driver, String url, String user, S
315315
}
316316
throw new SQLException("Driver " + driver + " is not suitable for " + url, "08001");
317317
} else if (javax.naming.Context.class.isAssignableFrom(d)) {
318+
if (!url.startsWith("java:")) {
319+
throw new SQLException("Only java scheme is supported for JNDI lookups", "08001");
320+
}
318321
// JNDI context
319322
Context context = (Context) d.getDeclaredConstructor().newInstance();
320323
DataSource ds = (DataSource) context.lookup(url);

h2/src/test/org/h2/test/unit/TestTools.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,13 @@ private void testJdbcDriverUtils() {
531531
} catch (SQLException e) {
532532
assertEquals("08001", e.getSQLState());
533533
}
534+
try {
535+
JdbcUtils.getConnection("javax.naming.InitialContext", "ldap://localhost/ds", "sa", "");
536+
fail("Expected SQLException: 08001");
537+
} catch (SQLException e) {
538+
assertEquals("08001", e.getSQLState());
539+
assertEquals("Only java scheme is supported for JNDI lookups", e.getMessage());
540+
}
534541
}
535542

536543
private void testWrongServer() throws Exception {

0 commit comments

Comments
 (0)