Bugfix/bacnet device string use after free#1375
Merged
Merged
Conversation
…, improving memory management and preventing use-after-free issues.
…ameter, enhancing memory management and preventing use-after-free issues.
…fers, where the API set calls use static memory and WriteProperty uses dynamic memory.
…lization. Fix property encoding to use application encoding.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the “basic server” Device object implementation to avoid use-after-free risks by storing writable Device string properties in managed BACNET_CHARACTER_STRING_BUFFER instances, and adds support for exposing PROP_DEVICE_UUID via ReadProperty.
Changes:
- Replace several Device string properties (name/vendor/model/etc.) from raw
const char *storage toBACNET_CHARACTER_STRING_BUFFER. - Update Device ReadProperty/WriteProperty paths to encode from buffers and to duplicate incoming strings for writable properties.
- Extend
bacstrwith new buffer helpers (*_ansi_length_init,*_ansi_strndup,characterstring_buffer_same) to support the new storage approach.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 12 comments.
| File | Description |
|---|---|
| src/bacnet/basic/server/bacnet_device.c | Migrates Device string properties to buffer-backed storage, updates Read/WriteProperty encoding, and adds PROP_DEVICE_UUID read support. |
| src/bacnet/bacstr.h | Declares new BACNET_CHARACTER_STRING_BUFFER helper APIs used by the server device object. |
| src/bacnet/bacstr.c | Implements new buffer helper functions used for initialization, duplication, and comparisons. |
Comments suppressed due to low confidence (1)
src/bacnet/bacstr.c:1070
- characterstring_buffer_ansi_length_init() documents that value may be NULL for an empty string, but it currently stores buffer=NULL. Downstream encoders (e.g., encode_bacnet_character_string_buffer) treat buffer==NULL as malformed and encode 0 bytes. This makes NULL inputs break ReadProperty encoding and breaks callers that use NULL to mean “reset/empty”.
characterstring_buffer_free(char_string);
char_string->encoding = CHARACTER_UTF8;
char_string->buffer = (char *)value;
char_string->buffer_size = length;
char_string->buffer_length = length;
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.
No description provided.