Skip to content

Commit

Permalink
Fix Ender 3 V2 (DWIN) buffer overrun (MarlinFirmware#19268)
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmoderp authored Sep 6, 2020
1 parent 4867311 commit 86b71b8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Marlin/src/lcd/dwin/dwin_lcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
#include "dwin_lcd.h"
#include <string.h> // for memset

// Make sure DWIN_SendBuf is large enough to hold the largest
// printed string plus the draw command and tail.
uint8_t DWIN_SendBuf[11 + 24] = { 0xAA };
// Make sure DWIN_SendBuf is large enough to hold the largest string plus draw command and tail.
// Assume the narrowest (6 pixel) font and 2-byte gb2312-encoded characters.
uint8_t DWIN_SendBuf[11 + DWIN_WIDTH / 6 * 2] = { 0xAA };
uint8_t DWIN_BufTail[4] = { 0xCC, 0x33, 0xC3, 0x3C };
uint8_t databuf[26] = { 0 };
uint8_t receivedType;
Expand All @@ -63,7 +63,7 @@ inline void DWIN_Long(size_t &i, const uint32_t lval) {
}

inline void DWIN_String(size_t &i, char * const string) {
const size_t len = strlen(string);
const size_t len = _MIN(sizeof(DWIN_SendBuf) - i, strlen(string));
memcpy(&DWIN_SendBuf[i+1], string, len);
i += len;
}
Expand Down

0 comments on commit 86b71b8

Please sign in to comment.