ConfigIntOption(Converter& c,
const std::string* snort_opt,
const std::string* table,
- const std::string* lua_opt) :
+ const std::string* lua_opt,
+ int max_int_value) :
ConversionState(c),
snort_option(snort_opt),
lua_table(table),
- lua_option(lua_opt)
+ lua_option(lua_opt),
+ max_value(max_int_value)
{
}
-
bool convert(std::istringstream& stream) override
{
if ((snort_option == nullptr) ||
// if the two names are not equal ...
if ((lua_option != nullptr) && *snort_option != *lua_option)
{
- retval = parse_int_option(*lua_option, stream, false);
+ if (max_value)
+ retval = parse_max_int_option(*lua_option, stream, max_value, false);
+ else
+ retval = parse_int_option(*lua_option, stream, false);
+
table_api.add_diff_option_comment("config " + *snort_option + ":", *lua_option);
}
else
{
- retval = parse_int_option(*snort_option, stream, false);
+ if (max_value)
+ retval = parse_max_int_option(*snort_option, stream, max_value, false);
+ else
+ retval = parse_int_option(*snort_option, stream, false);
}
table_api.close_table();
const std::string* snort_option;
const std::string* lua_table;
const std::string* lua_option;
+ const int max_value;
};
template<const std::string* snort_option,
-const std::string* lua_table,
-const std::string* lua_option = nullptr>
+ const std::string* lua_table,
+ const std::string* lua_option = nullptr,
+ int max_int_value = 0>
static ConversionState* config_int_ctor(Converter& c)
{
- return new ConfigIntOption(c, snort_option, lua_table, lua_option);
+ return new ConfigIntOption(c, snort_option, lua_table, lua_option, max_int_value);
}
} // namespace
static const ConvertMap max_mpls_labelchain_len_api =
{
max_mpls_labelchain_len,
- config_int_ctor<& max_mpls_labelchain_len,
- & mpls,
- & max_mpls_stack_depth>,
+ config_int_ctor<&max_mpls_labelchain_len,
+ &mpls,
+ &max_mpls_stack_depth,
+ 255>,
};
const ConvertMap* max_mpls_labelchain_len_map = &max_mpls_labelchain_len_api;
return false;
}
+ // Reduces int value to max value if value > max value
+ inline bool parse_max_int_option(const std::string& opt_name,
+ std::istringstream& stream, int max, bool append)
+ {
+ int val;
+
+ if (stream >> val)
+ {
+ if (val > max)
+ {
+ table_api.add_comment("option value reduced to maximum: '" + opt_name + "'");
+ val = max;
+ }
+
+ if (append)
+ table_api.append_option(opt_name, val);
+ else
+ table_api.add_option(opt_name, val);
+ return true;
+ }
+
+ table_api.add_comment("snort.conf missing argument for: " + opt_name + " <int>");
+ return false;
+ }
+
// Like parse_int_option() but reverses -1 and 0 values
inline bool parse_int_option_reverse_m10(const std::string& opt_name,
std::istringstream& stream)
}
else if (keyword == "max_command_line_len")
{
- tmpval = parse_int_option("max_command_line_len", data_stream, false);
+ tmpval = parse_max_int_option("max_command_line_len", data_stream, 65535, false);
}
else if (keyword == "max_header_line_len")
{
- tmpval = parse_int_option("max_header_line_len", data_stream, false);
+ tmpval = parse_max_int_option("max_header_line_len", data_stream, 65535, false);
}
else if (keyword == "max_response_line_len")
{
- tmpval = parse_int_option("max_response_line_len", data_stream, false);
+ tmpval = parse_max_int_option("max_response_line_len", data_stream, 65535, false);
}
else if (keyword == "normalize")
{