Skip to content

Commit

Permalink
Update draw method to prevent buffer overflow.
Browse files Browse the repository at this point in the history
- Adjusted buffer size calculation in the draw method of BaseWidgetValue and WidgetBool classes to avoid potential buffer overflow issues.
  • Loading branch information
forntoh committed Oct 21, 2024
1 parent d9ace60 commit 9acf555
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/widget/BaseWidgetValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class BaseWidgetValue : public BaseWidget {
*/
uint8_t draw(char* buffer, const uint8_t start) override {
if (start >= ITEM_DRAW_BUFFER_SIZE) return 0;
return snprintf(buffer + start, ITEM_DRAW_BUFFER_SIZE, format, value);
return snprintf(buffer + start, ITEM_DRAW_BUFFER_SIZE - start, format, value);
}

bool process(LcdMenu* menu, unsigned char command) override = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/widget/WidgetBool.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class WidgetBool : public BaseWidgetValue<bool> {
protected:
uint8_t draw(char* buffer, const uint8_t start) override {
if (start >= ITEM_DRAW_BUFFER_SIZE) return 0;
return snprintf(buffer + start, ITEM_DRAW_BUFFER_SIZE, format, value ? textOn : textOff);
return snprintf(buffer + start, ITEM_DRAW_BUFFER_SIZE - start, format, value ? textOn : textOff);
}
/**
* @brief Process command.
Expand Down

0 comments on commit 9acf555

Please sign in to comment.