Skip to content

Commit f92f478

Browse files
cosmoderpvgadreau
authored andcommitted
Fix Ender 3 V2 (DWIN) buffer overrun (MarlinFirmware#19268)
1 parent 2f8fb55 commit f92f478

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Marlin/src/lcd/dwin/dwin_lcd.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
#include "dwin_lcd.h"
3838
#include <string.h> // for memset
3939

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

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

0 commit comments

Comments
 (0)