From 8fc632f2b6fcc10717cd096da6ab957159f93e93 Mon Sep 17 00:00:00 2001 From: Wiebe Cazemier Date: Tue, 18 May 2021 20:01:21 +0200 Subject: [PATCH] Fix crashing config file parser by very long lines --- configfileparser.cpp | 6 ++++++ main.cpp | 6 ++++++ 2 files changed, 12 insertions(+), 0 deletions(-) diff --git a/configfileparser.cpp b/configfileparser.cpp index ed42b99..3e72711 100644 --- a/configfileparser.cpp +++ b/configfileparser.cpp @@ -138,6 +138,12 @@ void ConfigFileParser::loadFile(bool test) if (line.empty()) continue; + // The regex matcher can be made to crash on very long lines, so we're protecting ourselves. + if (line.length() > 256) + { + throw ConfigFileException(formatString("Error at line %d in '%s': line suspiciouly long.", linenr, path.c_str())); + } + std::smatch matches; const bool blockStartMatch = std::regex_search(line, matches, block_regex_start); diff --git a/main.cpp b/main.cpp index 6b69b66..05c9c13 100644 --- a/main.cpp +++ b/main.cpp @@ -85,6 +85,12 @@ int main(int argc, char *argv[]) logger->logf(LOG_NOTICE, "Starting FlashMQ"); mainApp->start(); } + catch (ConfigFileException &ex) + { + // Not using the logger here, because we may have had all sorts of init errors while setting it up. + std::cerr << ex.what() << std::endl; + return 99; + } catch (std::exception &ex) { // Not using the logger here, because we may have had all sorts of init errors while setting it up. -- libgit2 0.21.4