Merge pull request #3551 from wavexx/eof_crash_reentry

Prevent re-entry in EOF command processing
This commit is contained in:
DRracer 2022-08-19 17:07:21 +02:00 committed by GitHub
commit 2a0989c440
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 16 additions and 12 deletions

View File

@ -44,7 +44,7 @@ void print_hex_word(daddr_t val)
print_hex_byte(val & 0xFF); print_hex_byte(val & 0xFF);
} }
int parse_hex(char* hex, uint8_t* data, int count) int parse_hex(const char* hex, uint8_t* data, int count)
{ {
int parsed = 0; int parsed = 0;
while (*hex) while (*hex)

View File

@ -4248,7 +4248,7 @@ void process_commands()
*/ */
else if (code_seen_P(PSTR("M0")) || code_seen_P(PSTR("M1 "))) {// M0 and M1 - (Un)conditional stop - Wait for user button press on LCD else if (code_seen_P(PSTR("M0")) || code_seen_P(PSTR("M1 "))) {// M0 and M1 - (Un)conditional stop - Wait for user button press on LCD
char *src = strchr_pointer + 2; const char *src = strchr_pointer + 2;
codenum = 0; codenum = 0;
bool hasP = false, hasS = false; bool hasP = false, hasS = false;
if (code_seen('P')) { if (code_seen('P')) {
@ -5675,6 +5675,7 @@ eeprom_update_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM,0xFFFF);
{ {
// A new print has started from scratch, reset stats // A new print has started from scratch, reset stats
failstats_reset_print(); failstats_reset_print();
sdpos_atomic = 0;
#ifndef LA_NOCOMPAT #ifndef LA_NOCOMPAT
la10c_reset(); la10c_reset();
#endif #endif
@ -5773,7 +5774,7 @@ eeprom_update_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM,0xFFFF);
} }
starpos = (strchr(strchr_pointer + 4,'*')); starpos = (strchr(strchr_pointer + 4,'*'));
char* namestartpos = (strchr(strchr_pointer + 4,'!')); //find ! to indicate filename string start. const char* namestartpos = (strchr(strchr_pointer + 4,'!')); //find ! to indicate filename string start.
if(namestartpos==NULL) if(namestartpos==NULL)
{ {
namestartpos=strchr_pointer + 4; //default name position, 4 letters after the M namestartpos=strchr_pointer + 4; //default name position, 4 letters after the M
@ -5802,6 +5803,7 @@ eeprom_update_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM,0xFFFF);
{ {
// A new print has started from scratch, reset stats // A new print has started from scratch, reset stats
failstats_reset_print(); failstats_reset_print();
sdpos_atomic = 0;
#ifndef LA_NOCOMPAT #ifndef LA_NOCOMPAT
la10c_reset(); la10c_reset();
#endif #endif

View File

@ -1008,9 +1008,10 @@ void CardReader::flush_presort() {
void CardReader::printingHasFinished() void CardReader::printingHasFinished()
{ {
st_synchronize(); st_synchronize();
file.close();
if(file_subcall_ctr>0) //heading up to a parent file that called current as a procedure. if(file_subcall_ctr>0) //heading up to a parent file that called current as a procedure.
{ {
file.close();
file_subcall_ctr--; file_subcall_ctr--;
openFileReadFilteredGcode(filenames[file_subcall_ctr],true); openFileReadFilteredGcode(filenames[file_subcall_ctr],true);
setIndex(filespos[file_subcall_ctr]); setIndex(filespos[file_subcall_ctr]);
@ -1018,8 +1019,6 @@ void CardReader::printingHasFinished()
} }
else else
{ {
quickStop();
file.close();
sdprinting = false; sdprinting = false;
if(SD_FINISHED_STEPPERRELEASE) if(SD_FINISHED_STEPPERRELEASE)
{ {

View File

@ -534,7 +534,7 @@ void get_command()
} }
#ifdef SDSUPPORT #ifdef SDSUPPORT
if(!card.sdprinting || serial_count!=0){ if(!card.sdprinting || !card.isFileOpen() || serial_count!=0){
// If there is a half filled buffer from serial line, wait until return before // If there is a half filled buffer from serial line, wait until return before
// continuing with the serial line. // continuing with the serial line.
return; return;
@ -631,6 +631,10 @@ void get_command()
// cleared by printingHasFinished after peforming all remaining moves. // cleared by printingHasFinished after peforming all remaining moves.
if(!cmdqueue_calc_sd_length()) if(!cmdqueue_calc_sd_length())
{ {
// queue is complete, but before we process EOF commands prevent
// re-entry by disabling SD processing from any st_synchronize call
card.closefile();
SERIAL_PROTOCOLLNRPGM(_n("Done printing file"));////MSG_FILE_PRINTED SERIAL_PROTOCOLLNRPGM(_n("Done printing file"));////MSG_FILE_PRINTED
stoptime=_millis(); stoptime=_millis();
char time[30]; char time[30];

View File

@ -431,7 +431,7 @@ lcd_update_enable(true); // display / status-line recovery
#define GCODE_DELIMITER '"' #define GCODE_DELIMITER '"'
#define ELLIPSIS "..." #define ELLIPSIS "..."
char* code_string(char* pStr,size_t* nLength) char* code_string(const char* pStr,size_t* nLength)
{ {
char* pStrBegin; char* pStrBegin;
char* pStrEnd; char* pStrEnd;
@ -444,11 +444,10 @@ pStrEnd=strchr(pStrBegin,GCODE_DELIMITER);
if(!pStrEnd) if(!pStrEnd)
return(NULL); return(NULL);
*nLength=pStrEnd-pStrBegin; *nLength=pStrEnd-pStrBegin;
pStrBegin[*nLength] = '\0';
return pStrBegin; return pStrBegin;
} }
void printer_smodel_check(char* pStrPos) void printer_smodel_check(const char* pStrPos)
{ {
char* pResult; char* pResult;
size_t nLength,nPrinterNameLength; size_t nLength,nPrinterNameLength;
@ -458,7 +457,7 @@ pResult = code_string(pStrPos,&nLength);
if(pResult != NULL && nLength == nPrinterNameLength) { if(pResult != NULL && nLength == nPrinterNameLength) {
// Only compare them if the lengths match // Only compare them if the lengths match
if (strcmp_P(pResult, sPrinterName) == 0) return; if (strncmp_P(pResult, sPrinterName, nLength) == 0) return;
} }
switch(oCheckModel) switch(oCheckModel)

View File

@ -104,7 +104,7 @@ extern ClCheckGcode oCheckGcode;
void fCheckModeInit(); void fCheckModeInit();
void nozzle_diameter_check(uint16_t nDiameter); void nozzle_diameter_check(uint16_t nDiameter);
void printer_model_check(uint16_t nPrinterModel); void printer_model_check(uint16_t nPrinterModel);
void printer_smodel_check(char* pStrPos); void printer_smodel_check(const char* pStrPos);
void fw_version_check(const char *pVersion); void fw_version_check(const char *pVersion);
void gcode_level_check(uint16_t nGcodeLevel); void gcode_level_check(uint16_t nGcodeLevel);