Fix PROGMEM read in ErrorCode message
This could cause the printer to crash. The Serial Stream would show a garbled string. Also included in this commit: * The buffer size is increased from 64 bytes to 192 bytes. We need to take into account the length of the ErrorTitle and ErrorDescription. * Fix overwrite in ErrorCode message buffer.
This commit is contained in:
parent
52f7fb8c51
commit
6fab95f145
|
|
@ -609,10 +609,14 @@ void MMU2::ReportError(ErrorCode ec) {
|
||||||
lastErrorCode = ec;
|
lastErrorCode = ec;
|
||||||
|
|
||||||
// Log error format: MMU2:E=32766 TextDescription
|
// Log error format: MMU2:E=32766 TextDescription
|
||||||
char msg[64];
|
|
||||||
snprintf(msg, sizeof(msg), "MMU2:E=%hu", (uint16_t)ec);
|
// The longest error description in errors_list.h is 144 bytes.
|
||||||
|
// and the longest error title is 20 bytes. msg buffer needs
|
||||||
|
// to have enough space to fit both.
|
||||||
|
char msg[192];
|
||||||
|
int len = snprintf(msg, sizeof(msg), "MMU2:E=%hu", (uint16_t)ec);
|
||||||
// Append a human readable form of the error code(s)
|
// Append a human readable form of the error code(s)
|
||||||
TranslateErr((uint16_t)ec, msg, sizeof(msg));
|
TranslateErr((uint16_t)ec, &msg[len], 192 - len);
|
||||||
|
|
||||||
// beware - the prefix in the message ("MMU2") will get stripped by the logging subsystem
|
// beware - the prefix in the message ("MMU2") will get stripped by the logging subsystem
|
||||||
// and a correct MMU2 component will be assigned accordingly - see appmain.cpp
|
// and a correct MMU2 component will be assigned accordingly - see appmain.cpp
|
||||||
|
|
|
||||||
|
|
@ -92,9 +92,8 @@ void TranslateErr(uint16_t ec, char *dst, size_t dstSize) {
|
||||||
uint16_t ei = MMUErrorCodeIndex(ec);
|
uint16_t ei = MMUErrorCodeIndex(ec);
|
||||||
// just to prevent the compiler from stripping the data structures from the final binary for now
|
// just to prevent the compiler from stripping the data structures from the final binary for now
|
||||||
*dst = errorButtons[ei];
|
*dst = errorButtons[ei];
|
||||||
strncpy_P(dst + 1, errorTitles[ei], dstSize);
|
strncpy_P(dst + 1, static_cast<const char * const>(pgm_read_ptr(&errorTitles[ei])), dstSize);
|
||||||
strncat_P(dst, errorDescs[ei], dstSize);
|
strncat_P(dst, static_cast<const char * const>(pgm_read_ptr(&errorDescs[ei])), dstSize);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace MMU2
|
} // namespace MMU2
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue