"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/utils/js_identifier_ctx.cc" between
snort3-3.1.29.0.tar.gz and snort3-3.1.30.0.tar.gz

About: Snort 3 is a network intrusion prevention and detection system (IDS/IPS) combining the benefits of signature, protocol and anomaly-based inspection.

js_identifier_ctx.cc  (snort3-3.1.29.0):js_identifier_ctx.cc  (snort3-3.1.30.0)
skipping to change at line 51 skipping to change at line 51
class HttpModule class HttpModule
{ {
public: public:
static void increment_peg_counts(HttpEnums::PEG_COUNT) {} static void increment_peg_counts(HttpEnums::PEG_COUNT) {}
}; };
#endif // CATCH_TEST_BUILD #endif // CATCH_TEST_BUILD
#define NORM_NAME_SIZE 9 // size of the normalized form plus null symbol #define NORM_NAME_SIZE 9 // size of the normalized form plus null symbol
#define NORM_NAME_CNT 65536 #define NORM_NAME_CNT 65536
#define TYPE_NORMALIZED 1
#define TYPE_IGNORED_ID 2
#define TYPE_IGNORED_PROP 4
static char norm_names[NORM_NAME_SIZE * NORM_NAME_CNT]; static char norm_names[NORM_NAME_SIZE * NORM_NAME_CNT];
static void init_norm_names() static void init_norm_names()
{ {
static bool once = false; static bool once = false;
if (once) if (once)
return; return;
once = true; once = true;
skipping to change at line 82 skipping to change at line 86
*c++ = hex[(i >> 8) & 0xf]; *c++ = hex[(i >> 8) & 0xf];
*c++ = hex[(i >> 4) & 0xf]; *c++ = hex[(i >> 4) & 0xf];
*c++ = hex[(i >> 0) & 0xf]; *c++ = hex[(i >> 0) & 0xf];
*c++ = '\0'; *c++ = '\0';
} }
assert(sizeof(norm_names) == c - norm_names); assert(sizeof(norm_names) == c - norm_names);
} }
JSIdentifierCtx::JSIdentifierCtx(int32_t depth, uint32_t max_scope_depth, JSIdentifierCtx::JSIdentifierCtx(int32_t depth, uint32_t max_scope_depth,
const std::unordered_set<std::string>& ignore_list) const std::unordered_set<std::string>& ignored_ids_list,
: ignore_list(ignore_list), max_scope_depth(max_scope_depth) const std::unordered_set<std::string>& ignored_props_list)
: ignored_ids_list(ignored_ids_list), ignored_props_list(ignored_props_list)
,
max_scope_depth(max_scope_depth)
{ {
init_norm_names(); init_norm_names();
memset(id_fast, 0, sizeof(id_fast));
norm_name = norm_names; norm_name = norm_names;
norm_name_end = norm_names + NORM_NAME_SIZE * std::min(depth, NORM_NAME_CNT) ; norm_name_end = norm_names + NORM_NAME_SIZE * std::min(depth, NORM_NAME_CNT) ;
scopes.emplace_back(JSProgramScopeType::GLOBAL); scopes.emplace_back(JSProgramScopeType::GLOBAL);
for (const auto& iid : ignore_list) init_ignored_names();
if (iid.length() == 1)
id_fast[(unsigned)iid[0]] = iid.c_str();
else
id_names[iid] = iid.c_str();
} }
const char* JSIdentifierCtx::substitute(unsigned char c) const char* JSIdentifierCtx::substitute(unsigned char c, bool is_property)
{ {
auto p = id_fast[c]; auto p = id_fast[c];
if (p) if (is_substituted(p, is_property))
return p; return is_property ? p.prop_name : p.id_name;
if (norm_name >= norm_name_end)
return nullptr;
auto n = norm_name;
norm_name += NORM_NAME_SIZE;
HttpModule::increment_peg_counts(HttpEnums::PEG_JS_IDENTIFIER);
return id_fast[c] = n; return acquire_norm_name(id_fast[c]);
} }
const char* JSIdentifierCtx::substitute(const char* id_name) const char* JSIdentifierCtx::substitute(const char* id_name, bool is_property)
{ {
assert(*id_name); assert(*id_name);
if (id_name[1] == '\0') if (id_name[1] == '\0')
return substitute(*id_name); return substitute(*id_name, is_property);
const auto it = id_names.find(id_name); const auto it = id_names.find(id_name);
if (it != id_names.end()) if (it != id_names.end() && is_substituted(it->second, is_property))
return it->second; return is_property ? it->second.prop_name : it->second.id_name;
return acquire_norm_name(id_names[id_name]);
}
bool JSIdentifierCtx::is_ignored(const char* id_name) const
{
return id_name < norm_names ||
id_name >= norm_names + NORM_NAME_SIZE * NORM_NAME_CNT;
}
bool JSIdentifierCtx::is_substituted(const NormId& id, bool is_property)
{
return ((id.type & TYPE_NORMALIZED) != 0) ||
(!is_property && ((id.type & TYPE_IGNORED_ID) != 0)) ||
(is_property && ((id.type & TYPE_IGNORED_PROP) != 0));
}
const char* JSIdentifierCtx::acquire_norm_name(NormId& id)
{
if (norm_name >= norm_name_end) if (norm_name >= norm_name_end)
return nullptr; return nullptr;
auto n = norm_name; auto n = norm_name;
norm_name += NORM_NAME_SIZE; norm_name += NORM_NAME_SIZE;
HttpModule::increment_peg_counts(HttpEnums::PEG_JS_IDENTIFIER); HttpModule::increment_peg_counts(HttpEnums::PEG_JS_IDENTIFIER);
return id_names[id_name] = n; if (id.prop_name || id.id_name)
{
id.type |= TYPE_NORMALIZED;
if ((id.type & TYPE_IGNORED_ID) != 0)
return id.prop_name = n;
else if ((id.type & TYPE_IGNORED_PROP) != 0)
return id.id_name = n;
}
return (id = {n, n, TYPE_NORMALIZED}).id_name;
} }
bool JSIdentifierCtx::is_ignored(const char* id_name) const void JSIdentifierCtx::init_ignored_names()
{ {
return id_name < norm_names || for (const auto& iid : ignored_ids_list)
id_name >= norm_names + NORM_NAME_SIZE * NORM_NAME_CNT; if (iid.length() == 1)
id_fast[(unsigned)iid[0]] = {iid.c_str(), nullptr, TYPE_IGNORED_ID};
else
id_names[iid] = {iid.c_str(), nullptr, TYPE_IGNORED_ID};
for (const auto& iprop : ignored_props_list)
{
if (iprop.length() == 1)
{
id_fast[(unsigned)iprop[0]].prop_name = iprop.c_str();
id_fast[(unsigned)iprop[0]].type |= TYPE_IGNORED_PROP;
}
else
{
id_names[iprop].prop_name = iprop.c_str();
id_names[iprop].type |= TYPE_IGNORED_PROP;
}
}
} }
bool JSIdentifierCtx::scope_push(JSProgramScopeType t) bool JSIdentifierCtx::scope_push(JSProgramScopeType t)
{ {
assert(t != JSProgramScopeType::GLOBAL && t != JSProgramScopeType::PROG_SCOP E_TYPE_MAX); assert(t != JSProgramScopeType::GLOBAL && t != JSProgramScopeType::PROG_SCOP E_TYPE_MAX);
if (scopes.size() >= max_scope_depth) if (scopes.size() >= max_scope_depth)
return false; return false;
scopes.emplace_back(t); scopes.emplace_back(t);
skipping to change at line 167 skipping to change at line 205
if (scopes.back().type() != t) if (scopes.back().type() != t)
return false; return false;
assert(scopes.size() != 1); assert(scopes.size() != 1);
scopes.pop_back(); scopes.pop_back();
return true; return true;
} }
void JSIdentifierCtx::reset() void JSIdentifierCtx::reset()
{ {
memset(id_fast, 0, sizeof(id_fast)); memset(&id_fast, 0, sizeof(id_fast));
norm_name = norm_names; norm_name = norm_names;
id_names.clear(); id_names.clear();
scopes.clear(); scopes.clear();
scopes.emplace_back(JSProgramScopeType::GLOBAL); scopes.emplace_back(JSProgramScopeType::GLOBAL);
init_ignored_names();
for (const auto& iid : ignore_list)
if (iid.length() == 1)
id_fast[(unsigned)iid[0]] = iid.c_str();
else
id_names[iid] = iid.c_str();
} }
void JSIdentifierCtx::add_alias(const char* alias, const std::string&& value) void JSIdentifierCtx::add_alias(const char* alias, const std::string&& value)
{ {
assert(alias); assert(alias);
assert(!scopes.empty()); assert(!scopes.empty());
auto& a = aliases[alias]; auto& a = aliases[alias];
a.emplace_back(std::move(value)); a.emplace_back(std::move(value));
 End of changes. 16 change blocks. 
34 lines changed or deleted 68 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)