Avoid out-of-bounds access on global data#14363
Merged
OhadMeir merged 1 commit intoOct 21, 2025
Merged
Conversation
Contributor
|
Can one of the admins verify this patch? |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR ensures construction of a std::string from a non-NUL-terminated generated char array without invoking strlen, preventing out-of-bounds reads and eliminating an unnecessary 10KB scan.
- Replace implicit C-string constructor (which called strlen) with length-aware constructor using sizeof.
- Add an explanatory comment about lack of NUL termination.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
OhadMeir
approved these changes
Oct 21, 2025
Contributor
|
@torstenbaer thank you for the contribution. An internal ticket have been created to add automatic address sanitizer checks for viewer code, currently only SDK is checked. |
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.
The issue can be easily seen with the address sanitizer. 'realsense_udev_rules' is a generated char[] that is not NUL-terminated. Assigning to a std::string involves a strlen() call. Obviously, that call cannot find the NUL in the char array and thus accesses at least one byte outside of that buffer.
We could alternatively ensure that the generated buffer is NUL-terminated (not sure, whether there are other such generated char arrays), or we could provide the actual length to the constructor.
I have chosen the latter one here, because it avoids the strlen() call (roughly 10KB to scan).
This fixes the issue 14356.