fix(services): decode GetEventInformation without object identifier - #190
Open
chowchin wants to merge 1 commit into
Open
fix(services): decode GetEventInformation without object identifier#190chowchin wants to merge 1 commit into
chowchin wants to merge 1 commit into
Conversation
The lastReceivedObjectIdentifier of a GetEventInformation request is optional (ASHRAE 135, 13.12.1.1). A client requesting the first batch of events omits it, which results in a service request without any payload, but the decoder read the identifier unconditionally and therefore ran past the end of the buffer. The resulting RangeError is raised inside the transport message handler, where application code cannot catch it, so a single such request terminates the process of any device using this library to serve BACnet requests. Decode the identifier only when it is actually present.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
lastReceivedObjectIdentifierin a GetEventInformation request is optional (ASHRAE 135, 13.12.1.1). A client asking for the first batch of events omits it, so the request carries no service payload — butgetEventInformation.decodereads the identifier unconditionally and runs past the end of the buffer.The
RangeErroris raised inside thedgrammessage handler (_receiveData→_handleNpdu→_handlePdu→_processConfirmedServiceRequest), which application code cannot wrap, so one such request terminates the process of any device using bacstack to serve BACnet requests.Reproduction — a request with no payload is a 10-byte datagram (BVLC 4 + NPDU 2 + APDU header 4), so
client.jscallsdecode(buffer, 10, 0):Observed in production against a BMS that polls for alarms: every scan killed the gateway process, the service manager restarted it, the BMS retried and killed it again.
Change
Decode the identifier only when it is actually present, using the
apduLenthatclient.jsalready passes, plus a check that the next tag really is context tag 0. When it is absent,lastReceivedObjectIdisnullandlenis0.The third parameter is optional, so existing callers that pass only
(buffer, offset)— including the current unit test — behave exactly as before.Tests
Two cases added to
test/unit/service-get-event-information.spec.js: a request without the optional identifier, and one whose buffer ends exactly at the offset.npm testpasses (33 suites, 119 tests).