Merge remote-tracking branch 'origin/topic/timw/2947-input-config-regex'

* origin/topic/timw/2947-input-config-regex:
  Reimplement fixes to handle commas at the end of config parser lines
  Revert "Convert config framework to use std::regex"
  Revert "GH-636: Fix regex to handle commas at the end of config parser lines"
This commit is contained in:
Tim Wojtulewicz 2023-04-13 08:57:22 -07:00
commit c5ce82143a
3 changed files with 28 additions and 17 deletions

12
CHANGES
View file

@ -1,3 +1,15 @@
6.0.0-dev.359 | 2023-04-13 08:57:22 -0700
* Reimplement fixes to handle commas at the end of config parser lines (Tim Wojtulewicz, Corelight)
* Revert "Convert config framework to use std::regex" (Tim Wojtulewicz, Corelight)
This reverts commit 65ee2287e9b74f861872d9e16b9c11fb300cfabd.
* Revert "GH-636: Fix regex to handle commas at the end of config parser lines" (Tim Wojtulewicz, Corelight)
This reverts commit 05bb50978905a6c3132b20eb2cfd246715f91356.
6.0.0-dev.355 | 2023-04-13 09:24:19 +0200
* logging/Manager: Fix crash for rotation format function not returning (Arne Welzel, Corelight)

View file

@ -1 +1 @@
6.0.0-dev.355
6.0.0-dev.359

View file

@ -2,11 +2,11 @@
#include "zeek/input/readers/config/Config.h"
#include <regex.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <cerrno>
#include <regex>
#include <sstream>
#include <unordered_set>
@ -181,34 +181,31 @@ bool Config::DoUpdate()
unseen_options.insert(i.first);
}
std::regex re;
try
{
std::string re_str = Fmt(
"^([^[:blank:]]+)[[:blank:]]+([^[:blank:]](.*[^[:blank:]%c])?)?[[:blank:]%c]*$",
set_separator[0], set_separator[0]);
re.assign(re_str, std::regex::extended);
}
catch ( const std::regex_error& e )
regex_t re;
if ( regcomp(&re, re_str.c_str(), REG_EXTENDED) )
{
Error(Fmt("Failed to compile regex: %s", e.what()));
Error(Fmt("Failed to compile regex."));
return true;
}
while ( GetLine(line) )
{
std::smatch match;
if ( ! std::regex_match(line, match, re) )
regmatch_t match[3];
if ( regexec(&re, line.c_str(), 3, match, 0) )
{
Warning(
Fmt("Could not parse '%s'; line has invalid format. Ignoring line.", line.c_str()));
continue;
}
std::string key = match[1].str();
std::string key = line.substr(match[1].rm_so, match[1].rm_eo - match[1].rm_so);
std::string value;
if ( match.size() > 2 )
value = match[2].str();
if ( match[2].rm_so > 0 )
value = line.substr(match[2].rm_so, match[2].rm_eo - match[2].rm_so);
auto typeit = option_types.find(key);
if ( typeit == option_types.end() )
@ -289,6 +286,8 @@ bool Config::DoUpdate()
}
}
regfree(&re);
if ( Info().mode != MODE_STREAM )
EndCurrentSend();