Procházet zdrojové kódy

Keep config parser safe after post-processing OOM

SybexXx před 1 dnem
rodič
revize
556bf23128

+ 11 - 2
code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp

@@ -595,8 +595,12 @@ bool ClassFlowPostProcessing::ReadParameter(FILE* pfile, string& aktparamgraph)
     }
 
     if (!InitNUMBERS()) {
-        LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Post-processing initialization failed; skipping PreValue loading");
-        return false;
+        disabled = true;
+        LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "Post-processing initialization failed; disabling this step and skipping its configuration");
+        // InitFlow() advances using aktparamgraph. Consume this entire section so a failed
+        // allocation cannot leave the parser on [PostProcessing] and recreate the flow forever.
+        while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) {}
+        return true;
     }
 
     while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph)) {
@@ -694,6 +698,10 @@ bool ClassFlowPostProcessing::InitNUMBERS() {
     }
 
     ESP_LOGD(TAG, "Anzahl NUMBERS: %d - DIGITS: %d, ANALOG: %d", name_numbers.size(), anzDIGIT, anzANALOG);
+    if (name_numbers.empty()) {
+        LogFile.WriteToFile(ESP_LOG_ERROR, TAG, "No digit or analog numbers are available for post-processing");
+        return false;
+    }
 
     for (int _num = 0; _num < name_numbers.size(); ++_num) {
         NumberPost *_number = new (std::nothrow) NumberPost;
@@ -812,6 +820,7 @@ string ClassFlowPostProcessing::ShiftDecimal(string in, int _decShift) {
 }
 
 bool ClassFlowPostProcessing::doFlow(string zwtime) {
+    if (disabled) return true;
     std::lock_guard<std::mutex> lock(preValueMutex);
     string zwvalue;
     time_t imagetime = flowTakeImage->getTimeImageTaken();