Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,11 @@ private static Flow buildFlow(
switch (flow.protocol.getType()) {
case Tcp, Udp, Sctp -> {
flow.sourcePort = parseIntFromObjectOrString(sourcePort.get(), "source port");
if (flow.sourcePort < 1 || flow.sourcePort > 65535) {
if (flow.sourcePort < 0 || flow.sourcePort > 65535) {
throw new IllegalArgumentException("invalid source port [" + sourcePort.get() + "]");
}
flow.destinationPort = parseIntFromObjectOrString(destinationPort.get(), "destination port");
if (flow.destinationPort < 1 || flow.destinationPort > 65535) {
if (flow.destinationPort < 0 || flow.destinationPort > 65535) {
throw new IllegalArgumentException("invalid destination port [" + destinationPort.get() + "]");
}
}
Expand Down Expand Up @@ -268,7 +268,7 @@ static byte[] toUint16(int num) {
*/
static int parseIntFromObjectOrString(Object o, String fieldName) {
if (o == null) {
return 0;
return -1;
} else if (o instanceof Number number) {
return number.intValue();
} else if (o instanceof String string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void testBeatsInvalidSourceIp() throws Exception {
public void testBeatsInvalidSourcePort() throws Exception {
@SuppressWarnings("unchecked")
var source = (Map<String, Object>) event.get("source");
source.put("port", 0);
source.put("port", -1);
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> testCommunityIdProcessor(event, null));
assertThat(e.getMessage(), containsString("invalid source port"));
}
Expand Down Expand Up @@ -298,9 +298,9 @@ public void testInvalidPort() throws Exception {
event = buildEvent();
@SuppressWarnings("unchecked")
var source = (Map<String, Object>) event.get("source");
source.put("port", 0);
source.put("port", -1);
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> testCommunityIdProcessor(event, null));
assertThat(e.getMessage(), containsString("invalid source port [0]"));
assertThat(e.getMessage(), containsString("invalid source port [-1]"));

event = buildEvent();
@SuppressWarnings("unchecked")
Expand All @@ -312,9 +312,9 @@ public void testInvalidPort() throws Exception {
event = buildEvent();
@SuppressWarnings("unchecked")
var source3 = (Map<String, Object>) event.get("destination");
source3.put("port", 0);
source3.put("port", -1);
e = expectThrows(IllegalArgumentException.class, () -> testCommunityIdProcessor(event, null));
assertThat(e.getMessage(), containsString("invalid destination port [0]"));
assertThat(e.getMessage(), containsString("invalid destination port [-1]"));

event = buildEvent();
@SuppressWarnings("unchecked")
Expand Down