Fix stack buffer overflow in Schedule_Weekly_Schedule_Set#1222
Merged
skarg merged 2 commits intobacnet-stack:masterfrom Feb 7, 2026
Merged
Fix stack buffer overflow in Schedule_Weekly_Schedule_Set#1222skarg merged 2 commits intobacnet-stack:masterfrom
skarg merged 2 commits intobacnet-stack:masterfrom
Conversation
The memcpy was using sizeof(BACNET_WEEKLY_SCHEDULE) instead of sizeof(BACNET_DAILY_SCHEDULE), causing it to read 6784 bytes from a 968-byte source buffer, leading to stack buffer overflow and segmentation fault in the test_schedule unit test. This fixes the test_schedule test failure detected by ASAN: ERROR: AddressSanitizer: stack-buffer-overflow on address ... READ of size 6784 at 0x... partially underflows this variable Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a memory-safety bug in the Schedule object implementation by correcting the memcpy() size used when setting a single daily schedule entry within Schedule_Weekly_Schedule_Set().
Changes:
- Correct
memcpy()length fromsizeof(BACNET_WEEKLY_SCHEDULE)tosizeof(BACNET_DAILY_SCHEDULE)when copying one array element.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
skarg
approved these changes
Feb 7, 2026
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.
Summary
Fix stack buffer overflow in Schedule_Weekly_Schedule_Set() function.
Problem
The memcpy in Schedule_Weekly_Schedule_Set() was using sizeof(BACNET_WEEKLY_SCHEDULE) instead of sizeof(BACNET_DAILY_SCHEDULE). This caused it to read 6784 bytes from a 968-byte source
buffer, leading to:
Stack buffer overflow detected by AddressSanitizer
Segmentation fault in test_schedule unit test
Test failure: 99% tests passed, 1 test failed
Root Cause
Fix
Changed the memcpy size parameter from sizeof(BACNET_WEEKLY_SCHEDULE) to sizeof(BACNET_DAILY_SCHEDULE) since we are copying a single daily schedule element to the array at the specified
index.
Test Results
All 262 tests now pass (100%)
No AddressSanitizer errors
test_schedule test now passes
Checklist
Code compiles cleanly
All tests pass
Tested with AddressSanitizer - no memory errors
Follows project coding style