Skip to content

Commit a98b2e0

Browse files
amarzialidevflow.devflow-routing-intake
andauthored
Avoid IndexOutOfBound when parsing dbInfo without host (#10835)
Avoid IndexOutOfBound when parsing dbInfo without host Co-authored-by: devflow.devflow-routing-intake <devflow.devflow-routing-intake@kubernetes.us1.ddbuild.io>
1 parent 243ec0b commit a98b2e0

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/jdbc/JDBCConnectionUrlParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ DBInfo.Builder doParse(final String jdbcUrl, final DBInfo.Builder builder) {
7373
String instanceName = null;
7474
final int hostIndex = jdbcUrl.indexOf("://");
7575

76-
if (hostIndex <= 0) {
76+
if (hostIndex <= 0 || jdbcUrl.length() == 3 + hostIndex) {
7777
return builder;
7878
}
7979

dd-java-agent/instrumentation/jdbc/src/test/groovy/JDBCConnectionUrlParserTest.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class JDBCConnectionUrlParserTest extends InstrumentationSpecification {
3232
"" | _
3333
"jdbc:" | _
3434
"jdbc::" | _
35+
"jdbc://" | _
3536
"bogus:string" | _
3637
}
3738

@@ -209,6 +210,8 @@ class JDBCConnectionUrlParserTest extends InstrumentationSpecification {
209210
"jdbc:sybase:Tds:dbhostname:2638/dbname" | null | "sybase" | "tds" | null | "dbhostname" | 2638 | null | "dbname"
210211
// unknown DB type
211212
"jdbc:testdb://myhost:9999/testdatabase" | null | "testdb" | null | null | "myhost" | 9999 | null | "testdatabase"
213+
// host missing
214+
"jdbc:testdb://" | null | "testdb" | null | null | null | null | null | null
212215
expected = new DBInfo.Builder().type(type).subtype(subtype).user(user).instance(instance).db(db).host(host).port(port).build()
213216
}
214217
}

0 commit comments

Comments
 (0)