Skip to content

Commit b787b0e

Browse files
authored
Minor bug fix for BrokerView#validateAllowedUri (#1900)
The wrong variable is being referenced in the nested loop. This does not cause the validation to actually break due to other checks done during the recursive call, but is incorrect either way. With this fix the counter needed tweaking for limiting the number of nested components as well. Follow on to #1847
1 parent ffa7e9f commit b787b0e

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

activemq-broker/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,8 @@ private static void validateAllowedUrl(String uriString) throws URISyntaxExcepti
610610
// Validate the URI does not contain VM transport
611611
private static void validateAllowedUri(URI uri, int depth) throws URISyntaxException {
612612
// Don't allow more than 5 nested URIs to prevent blowing the stack
613-
if (depth > 5) {
613+
// If we are greater than 4 then this is the 5th level of composite
614+
if (depth > 4) {
614615
throw new IllegalArgumentException("URI can't contain more than 5 nested composite URIs");
615616
}
616617

@@ -625,10 +626,10 @@ private static void validateAllowedUri(URI uri, int depth) throws URISyntaxExcep
625626
// Each URI could be a nested composite URI so call validateAllowedUri()
626627
// to validate it. This check if composite first so we don't add to
627628
// the recursive stack depth if there's a lot of URIs that are not composite
628-
if (URISupport.isCompositeURI(uri)) {
629+
if (URISupport.isCompositeURI(component)) {
629630
validateAllowedUri(component, depth);
630631
} else {
631-
validateAllowedScheme(uri.getScheme());
632+
validateAllowedScheme(component.getScheme());
632633
}
633634
}
634635
}

activemq-unit-tests/src/test/java/org/apache/activemq/jmx/JmxCreateNCTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,16 @@ public void testVmBridgeBlocked() throws Exception {
116116

117117
@Test
118118
public void testAddNetworkConnectorMaxComposite() throws Exception {
119+
// Should allow 5 nested (excludes first wrapper) so no exception thrown
120+
assertNotNull(proxy.addNetworkConnector(
121+
"static:(static:(static:(static:(static:(bad://localhost)))))"));
122+
119123
try {
120-
// verify nested composite URI with more than 5 levels is blocked
124+
// verify nested composite URI with more than 5 levels is blocked. This has 6 nested
125+
// (not including first wrapper url
121126
proxy.addNetworkConnector(
122127
"static:(failover:(failover:(failover:(failover:(failover:(tcp://localhost:0))))))");
123-
fail("Should have failed trying to add vm connector bridge");
128+
fail("Should have failed trying to add more than 5 connector bridges");
124129
} catch (IllegalArgumentException e) {
125130
assertEquals("URI can't contain more than 5 nested composite URIs", e.getMessage());
126131
}

0 commit comments

Comments
 (0)