Merge remote-tracking branch 'origin/topic/christian/fix-config-segfault'

* origin/topic/christian/fix-config-segfault:
  Btest tweak for improved type rendering in config framework errors and set types
  More precise type information in a config framework error message
  Explicitly don't support sets with multiple index types in input/config frameworks
This commit is contained in:
Johanna Amann 2021-01-21 11:27:14 +00:00
commit 079d4164c0
7 changed files with 49 additions and 8 deletions

View file

@ -832,7 +832,12 @@ bool Manager::IsCompatibleType(Type* t, bool atomic_only)
if ( ! t->IsSet() )
return false;
return IsCompatibleType(t->AsSetType()->GetIndices()->GetPureType().get(), true);
const auto& indices = t->AsSetType()->GetIndices();
if ( indices->GetTypes().size() != 1 )
return false;
return IsCompatibleType(indices->GetPureType().get(), true);
}
case TYPE_VECTOR:

View file

@ -10,6 +10,7 @@
#include <sstream>
#include <unordered_set>
#include "zeek/Desc.h"
#include "zeek/input/Manager.h"
#include "zeek/threading/SerialTypes.h"
@ -38,7 +39,7 @@ Config::Config(ReaderFrontend *frontend) : ReaderBackend(frontend)
if ( id->GetType()->Tag() == TYPE_RECORD ||
! Manager::IsCompatibleType(id->GetType().get()) )
{
option_types[id->Name()] = std::make_tuple(TYPE_ERROR, id->GetType()->Tag());
option_types[id->Name()] = std::make_tuple(TYPE_ERROR, id->GetType()->Tag(), id);
continue;
}
@ -49,7 +50,7 @@ Config::Config(ReaderFrontend *frontend) : ReaderBackend(frontend)
else if ( primary == TYPE_VECTOR )
secondary = id->GetType()->AsVectorType()->Yield()->Tag();
option_types[id->Name()] = std::make_tuple(primary, secondary);
option_types[id->Name()] = std::make_tuple(primary, secondary, id);
}
}
@ -212,8 +213,10 @@ bool Config::DoUpdate()
if ( std::get<0>((*typeit).second) == TYPE_ERROR )
{
ODesc d;
std::get<2>((*typeit).second)->GetType()->Describe(&d);
Warning(Fmt("Option '%s' has type '%s', which is not supported for file input. Ignoring line.",
key.c_str(), type_name(std::get<1>((*typeit).second))));
key.c_str(), d.Description()));
continue;
}

View file

@ -9,6 +9,7 @@
#include <memory>
#include <unordered_map>
#include "zeek/ID.h"
#include "zeek/input/ReaderBackend.h"
#include "zeek/threading/formatters/Ascii.h"
@ -50,7 +51,7 @@ private:
std::string empty_field;
std::unique_ptr<threading::Formatter> formatter;
std::unordered_map<std::string, std::tuple<TypeTag, TypeTag>> option_types;
std::unordered_map<std::string, std::tuple<TypeTag, TypeTag, zeek::detail::IDPtr>> option_types;
std::unordered_map<std::string, std::string> option_values;
};