Skip to content
This repository was archived by the owner on Mar 21, 2023. It is now read-only.

Commit 2025d36

Browse files
committed
IpAddressConversion caught wrong exception (#32)
The first try block caught a too specific version of the IllegalArgumentException, allowing the exception to unwind too much. Properly return null or the default value in this case. Fixes #28 (cherry picked from commit fc5b8a5)
1 parent 5cd12d6 commit 2025d36

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/main/java/org/graylog/plugins/pipelineprocessor/functions/ips/IpAddressConversion.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public IpAddress evaluate(FunctionArgs args, EvaluationContext context) {
4747
try {
4848
final InetAddress inetAddress = InetAddresses.forString(ipString);
4949
return new IpAddress(inetAddress);
50-
} catch (IllegalFormatException e) {
50+
} catch (IllegalArgumentException e) {
5151
final Optional<String> defaultValue = defaultParam.optional(args, context);
5252
if (!defaultValue.isPresent()) {
5353
return null;

src/test/java/org/graylog/plugins/pipelineprocessor/functions/FunctionsSnippetsTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,4 +443,13 @@ public void syslog() {
443443
assertThat(message.getField("prio4_facility")).isEqualTo("local4");
444444
assertThat(message.getField("prio4_level")).isEqualTo("Notice");
445445
}
446+
447+
@Test
448+
public void ipMatchingIssue28() {
449+
final Rule rule = parser.parseRule(ruleForTest(), false);
450+
final Message in = new Message("some message", "somehost.graylog.org", Tools.nowUTC());
451+
evaluateRule(rule, in);
452+
453+
assertThat(actionsTriggered.get()).isFalse();
454+
}
446455
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
rule "IP subnet"
2+
when
3+
cidr_match("10.20.30.0/24", to_ip($message.source))
4+
then
5+
trigger_test();
6+
end

0 commit comments

Comments
 (0)