Skip to content

Fix out-of-bounds read by clearing attribute descriptor#16

Open
xcengel wants to merge 1 commit intoGurux:masterfrom
xcengel:patch-1
Open

Fix out-of-bounds read by clearing attribute descriptor#16
xcengel wants to merge 1 commit intoGurux:masterfrom
xcengel:patch-1

Conversation

@xcengel
Copy link
Copy Markdown

@xcengel xcengel commented Mar 9, 2026

Description

Bug: An out-of-bounds read occurs in dlms_getLnMessages() when sending a SET request that spans multiple data blocks.

Root cause: The attribute descriptor is correctly included only in the first data block (SET-Request-First-DataBlock). However, p->attributeDescriptor was not cleared afterwards. When subsequent blocks (SET-Request-With-DataBlock) were being built, the code attempted to re-add the attribute descriptor, but bb_set2 had already advanced the buffer position past its end, causing an out-of-bounds read.

Fix: Added an else branch after the first-block case in development/src/dlms.c that sets p->attributeDescriptor = NULL. This ensures subsequent blocks no longer attempt to include the descriptor, preventing the out-of-bounds access.

Affected file

development/src/dlms.c — function dlms_getLnMessages()

How to reproduce

Send a SET request with a value large enough to require more than one data block (SET-Request-With-DataBlock). The out-of-bounds read occurs when building the second and subsequent blocks.

Testing

Verified that multi-block SET requests complete successfully after the fix, and single-block SET requests are unaffected.

Clear attribute descriptor after first data block to prevent out-of-bounds read.
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Mar 9, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant