Skip to content

Commit

Permalink
fix(bacnetip): fix validation logic on NPDU header
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Sep 13, 2024
1 parent cf4f32d commit 8d201d0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
15 changes: 10 additions & 5 deletions plc4go/protocols/bacnetip/readwrite/model/NPDU.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,6 @@ public static NPDU staticParse(ReadBuffer readBuffer, Integer npduLength) throws
NPDUControl control =
readSimpleField(
"control", readComplex(() -> NPDUControl.staticParse(readBuffer), readBuffer));
// Validation
if (!((control) != (null))) {
throw new ParseValidationException("control required for further processing");
}

Integer destinationNetworkAddress =
readOptionalField(
Expand All @@ -316,6 +312,13 @@ public static NPDU staticParse(ReadBuffer readBuffer, Integer npduLength) throws
"destinationLength",
readUnsignedShort(readBuffer, 8),
control.getDestinationSpecified());
// Validation
if (!(((((control.getDestinationSpecified()) && ((destinationNetworkAddress) != (null)))
&& ((destinationLength) != (null))))
|| ((((!(control.getDestinationSpecified())) && ((destinationNetworkAddress) == (null)))
&& ((destinationLength) == (null)))))) {
throw new ParseValidationException("inconsistent control");
}

List<Short> destinationAddress =
readCountArrayField(
Expand All @@ -335,6 +338,13 @@ public static NPDU staticParse(ReadBuffer readBuffer, Integer npduLength) throws
Short sourceLength =
readOptionalField(
"sourceLength", readUnsignedShort(readBuffer, 8), control.getSourceSpecified());
// Validation
if (!(((((control.getSourceSpecified()) && ((sourceNetworkAddress) != (null)))
&& ((sourceLength) != (null))))
|| ((((!(control.getSourceSpecified())) && ((sourceNetworkAddress) == (null)))
&& ((sourceLength) == (null)))))) {
throw new ParseValidationException("inconsistent control");
}

List<Short> sourceAddress =
readCountArrayField(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,21 @@
[type NPDU(uint 16 npduLength)
[simple uint 8 protocolVersionNumber ]
[simple NPDUControl control ]
[validation 'control != null' "control required for further processing" ]
[optional uint 16 destinationNetworkAddress 'control.destinationSpecified' ]
[optional uint 8 destinationLength 'control.destinationSpecified' ]
// TODO: check if we don't treat a optional as optional when the condition meets
[validation '(control.destinationSpecified && destinationNetworkAddress != null && destinationLength != null)
|| (!control.destinationSpecified && destinationNetworkAddress == null && destinationLength == null)'
"inconsistent control" ]
[array uint 8 destinationAddress count 'control.destinationSpecified ? destinationLength : 0' ]
// (destinationNetworkAddress(16bit) + destinationLength(8bit) + destinationLength)?
[virtual uint 16 destinationLengthAddon 'control.destinationSpecified ? (3 + destinationLength) : 0' ]
[optional uint 16 sourceNetworkAddress 'control.sourceSpecified' ]
[optional uint 8 sourceLength 'control.sourceSpecified' ]
// TODO: check if we don't treat a optional as optional when the condition meets
[validation '(control.sourceSpecified && sourceNetworkAddress != null && sourceLength != null)
|| (!control.sourceSpecified && sourceNetworkAddress == null && sourceLength == null)'
"inconsistent control" ]
[array uint 8 sourceAddress count 'control.sourceSpecified ? sourceLength : 0' ]
// (sourceNetworkAddress(16bit) + sourceLength(8bit) + sourceLength)?
[virtual uint 16 sourceLengthAddon 'control.sourceSpecified ? (3 + sourceLength) : 0' ]
Expand Down

0 comments on commit 8d201d0

Please sign in to comment.