Merge in SNORT/snort3 from ~OSHUMEIK/snort3:js_fix to master
Squashed commit of the following:
commit
478c1781f4c7385e48b55c7793b40ccb19cae152
Author: Oleksii Shumeiko <oshumeik@cisco.com>
Date: Mon Mar 28 18:38:01 2022 +0300
utils: fix tracking variable when the output buffer is reset
{ rem_bytes = depth; }
const char* take_script()
- { return out_buf.take_data(); }
+ { tokenizer.reset_output(); return out_buf.take_data(); }
const char* get_script() const
{ return out_buf.data(); }
JSRet process(size_t& bytes_in);
+ void reset_output()
+ { ignored_id_pos = -1; }
+
bool is_unescape_nesting_seen() const;
bool is_mixed_encoding_seen() const;
protected:
{false, false, false, false, false, false, false, false, false, false, false,}
};
- std::streampos ignored_id_pos = -1;
+ std::streampos ignored_id_pos;
struct FunctionIdentifier
{
bool operator< (const FunctionIdentifier& other) const
{"unescape", FuncType::UNESCAPE },
{"decodeURI", FuncType::UNESCAPE },
{"decodeURIComponent", FuncType::UNESCAPE },
- {"String.fromCharCode", FuncType::CHAR_CODE }
+ {"String.fromCharCode", FuncType::CHAR_CODE }
}};
const uint32_t max_bracket_depth;
tmp_buf(buf),
tmp_buf_size(buf_size),
tmp_cap_size(cap_size),
+ ignored_id_pos(-1),
max_bracket_depth(max_bracket_depth)
{
scope_stack.emplace(GLOBAL);
NORMALIZE_T(dat5, dat6, exp7, exp8);
NORM_COMBINED_S_2(dat5, dat6, exp9);
}
+
+ SECTION("normalized word in the previous PDU")
+ {
+ const char dat1[] = "!foo";
+ const char dat2[] = "()";
+ const char exp1[] = "!var_0000";
+ const char exp2[] = "()";
+
+ NORMALIZE_T(dat1, dat2, exp1, exp2);
+ }
+
+ SECTION("ignored word in the previous PDU")
+ {
+ const char dat1[] = "!eval";
+ const char dat2[] = "()";
+ const char exp1[] = "!eval";
+ const char exp2[] = "()";
+
+ NORMALIZE_T(dat1, dat2, exp1, exp2);
+ }
}
TEST_CASE("Scope tracking - basic","[JSNormalizer]")