From 5a39afb81b2f2c2b72a293b8bf38fdff4b1c3606 Mon Sep 17 00:00:00 2001 From: GMagician <3684609+GMagician@users.noreply.github.com> Date: Sat, 10 Feb 2018 21:14:22 +0100 Subject: [PATCH] [1.1.x] Memory overflow protection (#9563) --- Marlin/ultralcd.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index d34d0ef6ed..70547df585 100644 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -84,7 +84,7 @@ uint8_t lcd_status_update_delay = 1, // First update one loop delayed lcd_status_message_level; // Higher level blocks lower level #if ENABLED(STATUS_MESSAGE_SCROLLING) - #define MAX_MESSAGE_LENGTH max(2 * CHARSIZE * LCD_WIDTH, LONG_FILENAME_LENGTH) + #define MAX_MESSAGE_LENGTH max(CHARSIZE * 2 * (LCD_WIDTH), LONG_FILENAME_LENGTH) uint8_t status_scroll_pos = 0; #else #define MAX_MESSAGE_LENGTH CHARSIZE * (LCD_WIDTH) @@ -5204,7 +5204,7 @@ bool lcd_hasstatus() { return (lcd_status_message[0] != '\0'); } void lcd_setstatus(const char * const message, const bool persist) { if (lcd_status_message_level > 0) return; - strncpy(lcd_status_message, message, 3 * (LCD_WIDTH)); + strncpy(lcd_status_message, message, COUNT(lcd_status_message) - 1); lcd_finishstatus(persist); } @@ -5212,7 +5212,7 @@ void lcd_setstatusPGM(const char * const message, int8_t level) { if (level < 0) level = lcd_status_message_level = 0; if (level < lcd_status_message_level) return; lcd_status_message_level = level; - strncpy_P(lcd_status_message, message, 3 * (LCD_WIDTH)); + strncpy_P(lcd_status_message, message, COUNT(lcd_status_message) - 1); lcd_finishstatus(level > 0); } @@ -5221,7 +5221,7 @@ void lcd_status_printf_P(const uint8_t level, const char * const fmt, ...) { lcd_status_message_level = level; va_list args; va_start(args, fmt); - vsnprintf_P(lcd_status_message, 3 * (LCD_WIDTH), fmt, args); + vsnprintf_P(lcd_status_message, COUNT(lcd_status_message) - 1, fmt, args); va_end(args); lcd_finishstatus(level > 0); }