Browse Source

Fix Ender 3 V2 (DWIN) buffer overrun (#19268)

cosmoderp 4 years ago
parent
commit
86b71b83fa
No account linked to committer's email address
1 changed files with 4 additions and 4 deletions
  1. 4
    4
      Marlin/src/lcd/dwin/dwin_lcd.cpp

+ 4
- 4
Marlin/src/lcd/dwin/dwin_lcd.cpp View File

37
 #include "dwin_lcd.h"
37
 #include "dwin_lcd.h"
38
 #include <string.h> // for memset
38
 #include <string.h> // for memset
39
 
39
 
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 };
43
 uint8_t DWIN_BufTail[4] = { 0xCC, 0x33, 0xC3, 0x3C };
43
 uint8_t DWIN_BufTail[4] = { 0xCC, 0x33, 0xC3, 0x3C };
44
 uint8_t databuf[26] = { 0 };
44
 uint8_t databuf[26] = { 0 };
45
 uint8_t receivedType;
45
 uint8_t receivedType;
63
 }
63
 }
64
 
64
 
65
 inline void DWIN_String(size_t &i, char * const string) {
65
 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));
67
   memcpy(&DWIN_SendBuf[i+1], string, len);
67
   memcpy(&DWIN_SendBuf[i+1], string, len);
68
   i += len;
68
   i += len;
69
 }
69
 }

Loading…
Cancel
Save