Open
Conversation
Contributor
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThis PR ensures fixed-size configuration buffers are fully cleared before writing potentially smaller payloads into them, preventing leftover bytes from prior content from leaking into current values. Class diagram for badge configuration buffers and writersclassDiagram
class badge_cfg_struct {
uint8_t ble_devname[]
uint8_t splash_bm_bits[]
uint16_t splash_bm_w
uint16_t splash_bm_h
uint8_t splash_speedI
uint8_t splash_speedT
}
class ngctrl_c {
+uint8_t power_setting(uint8_t* val, uint16_t len)
+void cfg_ble_devname(uint8_t* name, uint16_t len)
+uint8_t flash_splash_screen(uint8_t* val, uint16_t len)
}
class config_c {
+void cfg_fallback()
}
ngctrl_c --> badge_cfg_struct : writes_ble_devname
ngctrl_c --> badge_cfg_struct : writes_splash_bm_fields
config_c --> badge_cfg_struct : initializes_fallback_splash
class BufferWriteBehavior {
+clear_ble_devname_before_write()
+clear_splash_bm_bits_before_write()
}
BufferWriteBehavior <|.. ngctrl_c
BufferWriteBehavior <|.. config_c
Flow diagram for clearing and updating splash screen bufferflowchart TD
A[flash_splash_screen called with val and len] --> B{len < 3?}
B -- Yes --> C[Return error -4]
B -- No --> D[Compute sz, w, h]
D --> E[tmos_memset badge_cfg.splash_bm_bits to 0 with sizeof badge_cfg.splash_bm_bits]
E --> F[tmos_memcpy from val offset 3 into badge_cfg.splash_bm_bits with size sz]
F --> G[Set badge_cfg.splash_bm_w to w]
G --> H[Set badge_cfg.splash_bm_h to h]
H --> I[Return success]
subgraph Fallback_config_path
J[cfg_fallback called] --> K[Compute splash_size as ALIGN_1BYTE splash.w times splash.h]
K --> L[memset badge_cfg.splash_bm_bits to 0 with sizeof badge_cfg.splash_bm_bits]
L --> M[memcpy splash.bits into badge_cfg.splash_bm_bits with size splash_size]
M --> N[Set badge_cfg.splash_bm_w to splash.w]
N --> O[Set badge_cfg.splash_bm_h to splash.h]
end
Flow diagram for clearing and updating BLE device name bufferflowchart TD
A[cfg_ble_devname called with name and len] --> B[tmos_memset badge_cfg.ble_devname to 0 with sizeof badge_cfg.ble_devname]
B --> C[tmos_memcpy name into badge_cfg.ble_devname with size len]
C --> D[Return]
File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've found 2 issues, and left some high level feedback:
- In
cfg_ble_devnameandflash_splash_screen, consider guarding thetmos_memcpycalls withmin(len, sizeof(...))(or an explicit length check) so that you cannot overflow the destination buffers if a larger-than-expected length is passed in. - In
cfg_fallbackyou usememset/memcpywhile inngctrl.cyou usetmos_memset/tmos_memcpy; it would be good to standardize on one set of APIs here for consistency and to avoid subtle behavioral differences on this platform.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `cfg_ble_devname` and `flash_splash_screen`, consider guarding the `tmos_memcpy` calls with `min(len, sizeof(...))` (or an explicit length check) so that you cannot overflow the destination buffers if a larger-than-expected length is passed in.
- In `cfg_fallback` you use `memset`/`memcpy` while in `ngctrl.c` you use `tmos_memset`/`tmos_memcpy`; it would be good to standardize on one set of APIs here for consistency and to avoid subtle behavioral differences on this platform.
## Individual Comments
### Comment 1
<location path="src/ngctrl.c" line_range="60-61" />
<code_context>
static void cfg_ble_devname(uint8_t *name, uint16_t len)
{
+ tmos_memset(badge_cfg.ble_devname, 0, sizeof(badge_cfg.ble_devname));
tmos_memcpy(badge_cfg.ble_devname, name, len);
}
</code_context>
<issue_to_address>
**🚨 issue (security):** Guard `len` against `badge_cfg.ble_devname` capacity when writing to the buffer.
Since this function now always operates on the full `ble_devname` buffer, please clamp or validate `len` so `tmos_memcpy` cannot write past `badge_cfg.ble_devname` (e.g., `len = MIN(len, sizeof(badge_cfg.ble_devname))` or return an error if too large).
</issue_to_address>
### Comment 2
<location path="src/config.c" line_range="33-34" />
<code_context>
badge_cfg.splash_speedT = 30; // ms
int splash_size = ALIGN_1BYTE(splash.w) * splash.h;
+ memset(badge_cfg.splash_bm_bits, 0, sizeof(badge_cfg.splash_bm_bits));
memcpy(badge_cfg.splash_bm_bits, splash.bits, splash_size);
badge_cfg.splash_bm_w = splash.w;
badge_cfg.splash_bm_h = splash.h;
</code_context>
<issue_to_address>
**issue (bug_risk):** Validate that `splash_size` fits into `badge_cfg.splash_bm_bits` before `memcpy`.
The new `memset` avoids stale data when the splash image is smaller than the buffer, but `memcpy` still assumes `splash_size <= sizeof(badge_cfg.splash_bm_bits)`. If `ALIGN_1BYTE(splash.w) * splash.h` can exceed the destination size (e.g., due to config or asset changes), this will overflow. Please add a bound check (or clamp) on `splash_size` against `sizeof(badge_cfg.splash_bm_bits)` before calling `memcpy`.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
closes #114
When a smaller buffer size is used, the non-overwritten bytes from the old buffer remain in memory, causing a mismatch/garbage data.
fix:
Added a 0 initialization to the buffer before copying the new data over to ensure no old bytes are left behind.
Summary by Sourcery
Ensure badge configuration buffers are cleared before copying new BLE device name and splash screen bitmap data to prevent stale bytes when shorter payloads are written.
Bug Fixes:
Enhancements: