Skip to content

Commit

Permalink
Check URL scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
katzyn committed Jan 4, 2022
1 parent 4a2e677 commit b24aa46
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions h2/src/main/org/h2/util/JdbcUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ public static Connection getConnection(String driver, String url, String user, S
}
throw new SQLException("Driver " + driver + " is not suitable for " + url, "08001");
} else if (javax.naming.Context.class.isAssignableFrom(d)) {
if (!url.startsWith("java:")) {
throw new SQLException("Only java scheme is supported for JNDI lookups", "08001");
}
// JNDI context
Context context = (Context) d.getDeclaredConstructor().newInstance();
DataSource ds = (DataSource) context.lookup(url);
Expand Down
7 changes: 7 additions & 0 deletions h2/src/test/org/h2/test/unit/TestTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,13 @@ private void testJdbcDriverUtils() {
} catch (SQLException e) {
assertEquals("08001", e.getSQLState());
}
try {
JdbcUtils.getConnection("javax.naming.InitialContext", "ldap://localhost/ds", "sa", "");
fail("Expected SQLException: 08001");
} catch (SQLException e) {
assertEquals("08001", e.getSQLState());
assertEquals("Only java scheme is supported for JNDI lookups", e.getMessage());
}
}

private void testWrongServer() throws Exception {
Expand Down

0 comments on commit b24aa46

Please sign in to comment.