"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/utils/js_tokenizer.l" 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_tokenizer.l  (snort3-3.1.29.0):js_tokenizer.l  (snort3-3.1.30.0)
skipping to change at line 1106 skipping to change at line 1106
<dqstr,unesc_dqstr>{HTML_TAG_SCRIPT_OPEN} { if (ext_script) { ECHO; } else { BEGIN(regst); RETURN(OPENING_TAG) } } <dqstr,unesc_dqstr>{HTML_TAG_SCRIPT_OPEN} { if (ext_script) { ECHO; } else { BEGIN(regst); RETURN(OPENING_TAG) } }
<dqstr,unesc_dqstr>{HTML_TAG_SCRIPT_CLOSE} { if (ext_script) { ECHO; } else { BEGIN(regst); RETURN(CLOSING_TAG) } } <dqstr,unesc_dqstr>{HTML_TAG_SCRIPT_CLOSE} { if (ext_script) { ECHO; } else { BEGIN(regst); RETURN(CLOSING_TAG) } }
<dqstr,unesc_dqstr>\\{CR}{LF} { /* skip */ } <dqstr,unesc_dqstr>\\{CR}{LF} { /* skip */ }
<dqstr,unesc_dqstr>\\{LF} { /* skip */ } <dqstr,unesc_dqstr>\\{LF} { /* skip */ }
<dqstr,unesc_dqstr>\\{CR} { /* skip */ } <dqstr,unesc_dqstr>\\{CR} { /* skip */ }
<dqstr,unesc_dqstr>{LINE_TERMINATORS} { BEGIN(regst); RETURN(BAD_TOKEN) } <dqstr,unesc_dqstr>{LINE_TERMINATORS} { BEGIN(regst); RETURN(BAD_TOKEN) }
<dqstr,unesc_dqstr>{LITERAL_DQ_STRING_SKIP} { dealias_append(); ECHO; } <dqstr,unesc_dqstr>{LITERAL_DQ_STRING_SKIP} { dealias_append(); ECHO; }
<dqstr,unesc_dqstr>{LITERAL_DQ_STRING_TEXT} { dealias_append(); ECHO; } <dqstr,unesc_dqstr>{LITERAL_DQ_STRING_TEXT} { dealias_append(); ECHO; }
<dqstr,unesc_dqstr><<EOF>> { RETURN(SCRIPT_CONTINUE) } <dqstr,unesc_dqstr><<EOF>> { RETURN(SCRIPT_CONTINUE) }
<dqstr>{UNICODE_ESCAPE_SEQUENCE} | <dqstr>{UNICODE_ESCAPE_SEQUENCE} |
<dqstr>{HEX_ESCAPE_SEQUENCE} { escaped_unicode(); } <dqstr>{HEX_ESCAPE_SEQUENCE} { escaped_unicode_utf_8(); }
<dqstr>{ESCAPED_CODE_POINT} { escaped_code_point(); } <dqstr>{ESCAPED_CODE_POINT} { escaped_code_point(); }
<unesc_dqstr>{UNICODE_ESCAPE_SEQUENCE} { set_encoding(IS_UBACKSLASH_2); e <unesc_dqstr>{UNICODE_ESCAPE_SEQUENCE} { set_encoding(IS_UBACKSLASH_2); e
scaped_unicode(); } scaped_unicode_utf_8(); }
<unesc_dqstr>{HEX_ESCAPE_SEQUENCE} { set_encoding(IS_XBACKSLASH); esc <unesc_dqstr>{HEX_ESCAPE_SEQUENCE} { set_encoding(IS_XBACKSLASH); esc
aped_unicode(); } aped_unicode_latin_1(); }
<unesc_dqstr>{ESCAPED_CODE_POINT} { set_encoding(IS_UCODEPOINT); esc aped_code_point(); } <unesc_dqstr>{ESCAPED_CODE_POINT} { set_encoding(IS_UCODEPOINT); esc aped_code_point(); }
<unesc_dqstr>{BYTE_ESCAPE_SEQUENCE} { set_encoding(IS_UBACKSLASH_1); e <unesc_dqstr>{BYTE_ESCAPE_SEQUENCE} { set_encoding(IS_UBACKSLASH_1); e
scaped_unicode(); } scaped_unicode_latin_1(); }
<unesc_dqstr>{PERCENT_ESCAPE_SEQUENCE} { set_encoding(IS_UPERCENT); escap <unesc_dqstr>{PERCENT_ESCAPE_SEQUENCE} { set_encoding(IS_UPERCENT); escap
ed_unicode(); } ed_unicode_utf_8(); }
<unesc_dqstr>{URL_ESCAPE_SEQUENCE} { set_encoding(IS_PERCENT); escape <unesc_dqstr>{URL_ESCAPE_SEQUENCE} { set_encoding(IS_PERCENT); escape
d_url_sequence(); } d_url_sequence_latin_1(); }
{LITERAL_SQ_STRING_START} { EXEC(literal_sq_string_start()) } {LITERAL_SQ_STRING_START} { EXEC(literal_sq_string_start()) }
<sqstr,unesc_sqstr>{LITERAL_SQ_STRING_END} { dealias_append(); ECHO; BEGIN(di vop); } <sqstr,unesc_sqstr>{LITERAL_SQ_STRING_END} { dealias_append(); ECHO; BEGIN(di vop); }
<sqstr,unesc_sqstr>{HTML_TAG_SCRIPT_OPEN} { if (ext_script) { ECHO; } else { BEGIN(regst); RETURN(OPENING_TAG) } } <sqstr,unesc_sqstr>{HTML_TAG_SCRIPT_OPEN} { if (ext_script) { ECHO; } else { BEGIN(regst); RETURN(OPENING_TAG) } }
<sqstr,unesc_sqstr>{HTML_TAG_SCRIPT_CLOSE} { if (ext_script) { ECHO; } else { BEGIN(regst); RETURN(CLOSING_TAG) } } <sqstr,unesc_sqstr>{HTML_TAG_SCRIPT_CLOSE} { if (ext_script) { ECHO; } else { BEGIN(regst); RETURN(CLOSING_TAG) } }
<sqstr,unesc_sqstr>\\{CR}{LF} { /* skip */ } <sqstr,unesc_sqstr>\\{CR}{LF} { /* skip */ }
<sqstr,unesc_sqstr>\\{LF} { /* skip */ } <sqstr,unesc_sqstr>\\{LF} { /* skip */ }
<sqstr,unesc_sqstr>\\{CR} { /* skip */ } <sqstr,unesc_sqstr>\\{CR} { /* skip */ }
<sqstr,unesc_sqstr>{LINE_TERMINATORS} { BEGIN(regst); RETURN(BAD_TOKEN) } <sqstr,unesc_sqstr>{LINE_TERMINATORS} { BEGIN(regst); RETURN(BAD_TOKEN) }
<sqstr,unesc_sqstr>{LITERAL_SQ_STRING_SKIP} { dealias_append(); ECHO; } <sqstr,unesc_sqstr>{LITERAL_SQ_STRING_SKIP} { dealias_append(); ECHO; }
<sqstr,unesc_sqstr>{LITERAL_SQ_STRING_TEXT} { dealias_append(); ECHO; } <sqstr,unesc_sqstr>{LITERAL_SQ_STRING_TEXT} { dealias_append(); ECHO; }
<sqstr,unesc_sqstr><<EOF>> { RETURN(SCRIPT_CONTINUE) } <sqstr,unesc_sqstr><<EOF>> { RETURN(SCRIPT_CONTINUE) }
<sqstr>{UNICODE_ESCAPE_SEQUENCE} | <sqstr>{UNICODE_ESCAPE_SEQUENCE} |
<sqstr>{HEX_ESCAPE_SEQUENCE} { escaped_unicode(); } <sqstr>{HEX_ESCAPE_SEQUENCE} { escaped_unicode_utf_8(); }
<sqstr>{ESCAPED_CODE_POINT} { escaped_code_point(); } <sqstr>{ESCAPED_CODE_POINT} { escaped_code_point(); }
<unesc_sqstr>{UNICODE_ESCAPE_SEQUENCE} { set_encoding(IS_UBACKSLASH_2); e <unesc_sqstr>{UNICODE_ESCAPE_SEQUENCE} { set_encoding(IS_UBACKSLASH_2); e
scaped_unicode(); } scaped_unicode_utf_8(); }
<unesc_sqstr>{HEX_ESCAPE_SEQUENCE} { set_encoding(IS_XBACKSLASH); esc <unesc_sqstr>{HEX_ESCAPE_SEQUENCE} { set_encoding(IS_XBACKSLASH); esc
aped_unicode(); } aped_unicode_latin_1(); }
<unesc_sqstr>{ESCAPED_CODE_POINT} { set_encoding(IS_UCODEPOINT); esc aped_code_point(); } <unesc_sqstr>{ESCAPED_CODE_POINT} { set_encoding(IS_UCODEPOINT); esc aped_code_point(); }
<unesc_sqstr>{BYTE_ESCAPE_SEQUENCE} { set_encoding(IS_UBACKSLASH_1); e <unesc_sqstr>{BYTE_ESCAPE_SEQUENCE} { set_encoding(IS_UBACKSLASH_1); e
scaped_unicode(); } scaped_unicode_latin_1(); }
<unesc_sqstr>{PERCENT_ESCAPE_SEQUENCE} { set_encoding(IS_UPERCENT); escap <unesc_sqstr>{PERCENT_ESCAPE_SEQUENCE} { set_encoding(IS_UPERCENT); escap
ed_unicode(); } ed_unicode_utf_8(); }
<unesc_sqstr>{URL_ESCAPE_SEQUENCE} { set_encoding(IS_PERCENT); escape <unesc_sqstr>{URL_ESCAPE_SEQUENCE} { set_encoding(IS_PERCENT); escape
d_url_sequence(); } d_url_sequence_latin_1(); }
{LITERAL_TEMPLATE_START} { EXEC(literal_temp late_start()) } {LITERAL_TEMPLATE_START} { EXEC(literal_temp late_start()) }
<tmpll,unesc_tmpll>(\\\\)*{LITERAL_TEMPLATE_END} { dealias_append(); ECHO; BEGIN(divop); } <tmpll,unesc_tmpll>(\\\\)*{LITERAL_TEMPLATE_END} { dealias_append(); ECHO; BEGIN(divop); }
<tmpll,unesc_tmpll>(\\\\)*{LITERAL_TEMPLATE_SUBST_START} { EXEC(process_subs t_open()) dealias_reset(); } <tmpll,unesc_tmpll>(\\\\)*{LITERAL_TEMPLATE_SUBST_START} { EXEC(process_subs t_open()) dealias_reset(); }
<tmpll,unesc_tmpll>{HTML_TAG_SCRIPT_CLOSE} { BEGIN(regst); RET URN(CLOSING_TAG) } <tmpll,unesc_tmpll>{HTML_TAG_SCRIPT_CLOSE} { BEGIN(regst); RET URN(CLOSING_TAG) }
<tmpll,unesc_tmpll>(\\\\)*\\{LITERAL_TEMPLATE_SUBST_START} | /* escaped templa te substitution */ <tmpll,unesc_tmpll>(\\\\)*\\{LITERAL_TEMPLATE_SUBST_START} | /* escaped templa te substitution */
<tmpll,unesc_tmpll>(\\\\)*\\{LITERAL_TEMPLATE_END} | /* escaped backti ck */ <tmpll,unesc_tmpll>(\\\\)*\\{LITERAL_TEMPLATE_END} | /* escaped backti ck */
<tmpll,unesc_tmpll>{LITERAL_TEMPLATE_OTHER} { dealias_append(); ECHO; } <tmpll,unesc_tmpll>{LITERAL_TEMPLATE_OTHER} { dealias_append(); ECHO; }
<tmpll,unesc_tmpll><<EOF>> { RETURN(SCRIPT_CON TINUE) } <tmpll,unesc_tmpll><<EOF>> { RETURN(SCRIPT_CON TINUE) }
<tmpll>{UNICODE_ESCAPE_SEQUENCE} | <tmpll>{UNICODE_ESCAPE_SEQUENCE} |
<tmpll>{HEX_ESCAPE_SEQUENCE} { escaped_unicode() ; } <tmpll>{HEX_ESCAPE_SEQUENCE} { escaped_unicode_u tf_8(); }
<tmpll>{ESCAPED_CODE_POINT} { escaped_code_poin t(); } <tmpll>{ESCAPED_CODE_POINT} { escaped_code_poin t(); }
<unesc_tmpll>{UNICODE_ESCAPE_SEQUENCE} { set_encoding(IS_U <unesc_tmpll>{UNICODE_ESCAPE_SEQUENCE} { set_encoding(IS_U
BACKSLASH_2); escaped_unicode(); } BACKSLASH_2); escaped_unicode_utf_8(); }
<unesc_tmpll>{HEX_ESCAPE_SEQUENCE} { set_encoding(IS_X <unesc_tmpll>{HEX_ESCAPE_SEQUENCE} { set_encoding(IS_X
BACKSLASH); escaped_unicode(); } BACKSLASH); escaped_unicode_latin_1(); }
<unesc_tmpll>{ESCAPED_CODE_POINT} { set_encoding(IS_U CODEPOINT); escaped_code_point(); } <unesc_tmpll>{ESCAPED_CODE_POINT} { set_encoding(IS_U CODEPOINT); escaped_code_point(); }
<unesc_tmpll>{BYTE_ESCAPE_SEQUENCE} { set_encoding(IS_U <unesc_tmpll>{BYTE_ESCAPE_SEQUENCE} { set_encoding(IS_U
BACKSLASH_1); escaped_unicode(); } BACKSLASH_1); escaped_unicode_latin_1(); }
<unesc_tmpll>{PERCENT_ESCAPE_SEQUENCE} { set_encoding(IS_U <unesc_tmpll>{PERCENT_ESCAPE_SEQUENCE} { set_encoding(IS_U
PERCENT); escaped_unicode(); } PERCENT); escaped_unicode_utf_8(); }
<unesc_tmpll>{URL_ESCAPE_SEQUENCE} { set_encoding(IS_P <unesc_tmpll>{URL_ESCAPE_SEQUENCE} { set_encoding(IS_P
ERCENT); escaped_url_sequence(); } ERCENT); escaped_url_sequence_latin_1(); }
<regst>{LITERAL_REGEX_START} { EXEC(literal_regex_start()) } <regst>{LITERAL_REGEX_START} { EXEC(literal_regex_start()) }
<regex>{LITERAL_REGEX_END} { EXEC(literal_regex_end()) } <regex>{LITERAL_REGEX_END} { EXEC(literal_regex_end()) }
<regex>{HTML_TAG_SCRIPT_CLOSE} { BEGIN(regst); RETURN(CLOSING_TAG) } <regex>{HTML_TAG_SCRIPT_CLOSE} { BEGIN(regst); RETURN(CLOSING_TAG) }
<regex>\\{LF} | <regex>\\{LF} |
<regex>\\{CR} | <regex>\\{CR} |
<regex>{LINE_TERMINATORS} { BEGIN(regst); RETURN(BAD_TOKEN) } <regex>{LINE_TERMINATORS} { BEGIN(regst); RETURN(BAD_TOKEN) }
<regex>{LITERAL_REGEX_SKIP} { ECHO; } <regex>{LITERAL_REGEX_SKIP} { ECHO; }
<regex>{LITERAL_REGEX_TEXT} { ECHO; } <regex>{LITERAL_REGEX_TEXT} { ECHO; }
<regex>{LITERAL_REGEX_G_OPEN} { EXEC(literal_regex_g_open()) } <regex>{LITERAL_REGEX_G_OPEN} { EXEC(literal_regex_g_open()) }
<regex>{LITERAL_REGEX_G_CLOSE} { EXEC(literal_regex_g_close()) } <regex>{LITERAL_REGEX_G_CLOSE} { EXEC(literal_regex_g_close()) }
<regex>{UNICODE_ESCAPE_SEQUENCE} | <regex>{UNICODE_ESCAPE_SEQUENCE} |
<regex>{HEX_ESCAPE_SEQUENCE} { escaped_unicode(); } <regex>{HEX_ESCAPE_SEQUENCE} { escaped_unicode_utf_8(); }
<regex><<EOF>> { RETURN(SCRIPT_CONTINUE) } <regex><<EOF>> { RETURN(SCRIPT_CONTINUE) }
<divop>{DIV_OPERATOR} | <divop>{DIV_OPERATOR} |
<divop>{DIV_ASSIGNMENT_OPERATOR} { div_assignment_operator(); } <divop>{DIV_ASSIGNMENT_OPERATOR} { div_assignment_operator(); }
{OPEN_BRACE} { EXEC(open_brace()) } {OPEN_BRACE} { EXEC(open_brace()) }
{CLOSE_BRACE} { EXEC(close_brace()) } {CLOSE_BRACE} { EXEC(close_brace()) }
{OPEN_PARENTHESIS} { EXEC(open_parenthesis()) } {OPEN_PARENTHESIS} { EXEC(open_parenthesis()) }
<INITIAL,divop,regst,char_code>{CLOSE_PARENTHESIS} { EXEC(close_parenthesis() ) } <INITIAL,divop,regst,char_code>{CLOSE_PARENTHESIS} { EXEC(close_parenthesis() ) }
{OPEN_BRACKET} { EXEC(open_bracket()) } {OPEN_BRACKET} { EXEC(open_bracket()) }
skipping to change at line 1503 skipping to change at line 1503
JSTokenizer::JSRet JSTokenizer::do_identifier_substitution(const char* lexeme, b ool id_part) JSTokenizer::JSRet JSTokenizer::do_identifier_substitution(const char* lexeme, b ool id_part)
{ {
if (!ident_norm() && id_part) if (!ident_norm() && id_part)
{ {
yyout << lexeme; yyout << lexeme;
return EOS; return EOS;
} }
set_ident_norm(true); set_ident_norm(true);
const char* name = ident_ctx.substitute(lexeme); const char* name = ident_ctx.substitute(lexeme, id_part);
if (!name) if (!name)
{ {
debug_logf(6, http_trace, TRACE_JS_DUMP, nullptr, debug_logf(6, http_trace, TRACE_JS_DUMP, nullptr,
"'%s' => IDENTIFIER_OVERFLOW\n", lexeme); "'%s' => IDENTIFIER_OVERFLOW\n", lexeme);
return IDENTIFIER_OVERFLOW; return IDENTIFIER_OVERFLOW;
} }
if (ident_ctx.is_ignored(name)) if (ident_ctx.is_ignored(name))
{ {
if (id_part) if (!id_part)
{
std::string n(name);
n.push_back('+'); // any illegal symbol as a part of ID name
name = ident_ctx.substitute(n.c_str());
}
else
{
ignored_id_pos = yyout.rdbuf()->pubseekoff(0, yyout.cur, std::ios_ba se::out); ignored_id_pos = yyout.rdbuf()->pubseekoff(0, yyout.cur, std::ios_ba se::out);
set_ident_norm(false); set_ident_norm(false);
yyout << name; yyout << name;
return EOS; return EOS;
}
} }
const char* alias = id_part ? nullptr : ident_ctx.alias_lookup(lexeme); const char* alias = id_part ? nullptr : ident_ctx.alias_lookup(lexeme);
if (alias) if (alias)
{ {
set_ident_norm(false); set_ident_norm(false);
ignored_id_pos = yyout.rdbuf()->pubseekoff(0, yyout.cur, std::ios_base:: out); ignored_id_pos = yyout.rdbuf()->pubseekoff(0, yyout.cur, std::ios_base:: out);
last_dealiased = std::string(YYText()); last_dealiased = std::string(YYText());
dealias_stored = true; dealias_stored = true;
skipping to change at line 1936 skipping to change at line 1928
JSTokenizer::FuncType JSTokenizer::detect_func_type() JSTokenizer::FuncType JSTokenizer::detect_func_type()
{ {
switch(token) switch(token)
{ {
case CLOSING_BRACKET: case CLOSING_BRACKET:
case KEYWORD: case KEYWORD:
return FuncType::GENERAL; return FuncType::GENERAL;
case IDENTIFIER: case IDENTIFIER:
{ if (meta_type() == ScopeMetaType::FUNCTION or ignored_id_pos < 0)
FuncType ret = FuncType::GENERAL; return FuncType::GENERAL;
if (meta_type() == ScopeMetaType::FUNCTION)
return ret;
if (ignored_id_pos >= 0)
{ {
char tail[256];
std::streambuf* pbuf = yyout.rdbuf(); std::streambuf* pbuf = yyout.rdbuf();
std::streamsize size = pbuf->pubseekoff(0, yyout.cur, yyout.out) - i gnored_id_pos; std::streamsize size = pbuf->pubseekoff(0, yyout.cur, yyout.out) - i gnored_id_pos;
assert(size >= 0);
char tail[256]; if (size <= 0)
assert((size_t)size <= sizeof(tail)); return FuncType::GENERAL;
size = std::min((size_t)size, sizeof(tail));
size = std::min((size_t)size, sizeof(tail));
pbuf->pubseekoff(-size, yyout.cur, yyout.out); pbuf->pubseekoff(-size, yyout.cur, yyout.out);
pbuf->sgetn(tail, size); pbuf->sgetn(tail, size);
for (const auto& id : function_identifiers) for (const auto& id : function_identifiers)
{ {
if ((unsigned)size == (unsigned)id.identifier.size() && if ((unsigned)size == (unsigned)id.identifier.size() &&
memcmp(tail, id.identifier.data(), size) == 0) memcmp(tail, id.identifier.data(), size) == 0)
{ {
ret = id.type;
pbuf->pubseekoff(-size, yyout.cur, yyout.out); pbuf->pubseekoff(-size, yyout.cur, yyout.out);
return id.type;
break;
} }
} }
return FuncType::GENERAL;
} }
return ret;
}
default: default:
return FuncType::NOT_FUNC; return FuncType::NOT_FUNC;
} }
} }
void JSTokenizer::check_function_nesting(JSTokenizer::FuncType type) void JSTokenizer::check_function_nesting(JSTokenizer::FuncType type)
{ {
switch (type) switch (type)
{ {
skipping to change at line 2085 skipping to change at line 2071
return true; return true;
default: default:
return false; return false;
} }
} }
void JSTokenizer::dealias_clear_mutated(bool id_continue) void JSTokenizer::dealias_clear_mutated(bool id_continue)
{ {
if (!id_continue && prefix_increment && dealias_stored) if (!id_continue && prefix_increment && dealias_stored)
{ {
ident_ctx.add_alias(last_dealiased.c_str(), std::string(ident_ctx.substi ident_ctx.add_alias(last_dealiased.c_str(),
tute(last_dealiased.c_str()))); std::string(ident_ctx.substitute(last_dealiased.c_str(), false)));
} }
dealias_stored = false; dealias_stored = false;
prefix_increment = false; prefix_increment = false;
} }
void JSTokenizer::dealias_increment() void JSTokenizer::dealias_increment()
{ {
if (dealias_stored) if (dealias_stored)
{ {
ident_ctx.add_alias(last_dealiased.c_str(), std::string(ident_ctx.substi ident_ctx.add_alias(last_dealiased.c_str(),
tute(last_dealiased.c_str()))); std::string(ident_ctx.substitute(last_dealiased.c_str(), false)));
} }
prefix_increment = token != IDENTIFIER && token != CLOSING_BRACKET; prefix_increment = token != IDENTIFIER && token != CLOSING_BRACKET;
dealias_stored = false; dealias_stored = false;
} }
void JSTokenizer::dealias_identifier(bool id_part, bool assignment_start) void JSTokenizer::dealias_identifier(bool id_part, bool assignment_start)
{ {
auto lexeme = YYText(); auto lexeme = YYText();
switch (alias_state) switch (alias_state)
skipping to change at line 2127 skipping to change at line 2115
case ALIAS_DEFINITION: case ALIAS_DEFINITION:
dealias_reset(); dealias_reset();
break; break;
case ALIAS_EQUALS: case ALIAS_EQUALS:
alias_state = ALIAS_VALUE; alias_state = ALIAS_VALUE;
// fallthrough // fallthrough
case ALIAS_VALUE: case ALIAS_VALUE:
{ {
auto dealias = ident_ctx.alias_lookup(lexeme); auto dealias = ident_ctx.alias_lookup(lexeme);
if ((!ident_norm() && id_part) || if ((!ident_norm() && id_part) ||
(ident_ctx.is_ignored(ident_ctx.substitute(lexeme)) && !id_part)) (!id_part && ident_ctx.is_ignored(ident_ctx.substitute(lexeme, false ))))
aliased << YYText(); aliased << YYText();
else if (dealias) else if (dealias)
aliased << dealias; aliased << dealias;
else else
dealias_reset(); dealias_reset();
break; break;
} }
} }
} }
void JSTokenizer::dealias_equals(bool complex_assignment) void JSTokenizer::dealias_equals(bool complex_assignment)
{ {
if (alias_state == ALIAS_DEFINITION || alias_state == ALIAS_PREFIX) if (alias_state == ALIAS_DEFINITION || alias_state == ALIAS_PREFIX)
{ {
if (complex_assignment) if (complex_assignment)
{ {
if (ident_ctx.alias_lookup(alias.c_str())) if (ident_ctx.alias_lookup(alias.c_str()))
ident_ctx.add_alias(alias.c_str(), std::string(ident_ctx.substit {
ute(alias.c_str()))); ident_ctx.add_alias(alias.c_str(),
std::string(ident_ctx.substitute(alias.c_str(), false)));
}
alias_state = ALIAS_NONE; alias_state = ALIAS_NONE;
} }
else else
alias_state = ALIAS_EQUALS; alias_state = ALIAS_EQUALS;
} }
} }
void JSTokenizer::dealias_reset() void JSTokenizer::dealias_reset()
{ {
if (alias_state != ALIAS_NONE) if (alias_state != ALIAS_NONE)
{ {
if (alias_state == ALIAS_VALUE || alias_state == ALIAS_EQUALS) if (alias_state == ALIAS_VALUE || alias_state == ALIAS_EQUALS)
if (ident_ctx.alias_lookup(alias.c_str())) if (ident_ctx.alias_lookup(alias.c_str()))
ident_ctx.add_alias(alias.c_str(), std::string(ident_ctx.substit {
ute(alias.c_str()))); ident_ctx.add_alias(alias.c_str(),
std::string(ident_ctx.substitute(alias.c_str(), false)));
}
alias_state = ALIAS_NONE; alias_state = ALIAS_NONE;
} }
} }
void JSTokenizer::dealias_prefix_reset() void JSTokenizer::dealias_prefix_reset()
{ {
if (alias_state == ALIAS_DEFINITION) if (alias_state == ALIAS_DEFINITION)
alias_state = ALIAS_PREFIX; alias_state = ALIAS_PREFIX;
else else
dealias_reset(); dealias_reset();
skipping to change at line 2309 skipping to change at line 2303
ECHO; ECHO;
return EOS; return EOS;
} }
} }
JSTokenizer::JSRet JSTokenizer::literal_regex_g_open() JSTokenizer::JSRet JSTokenizer::literal_regex_g_open()
{ {
if (regex_stack.size() >= max_template_nesting) if (regex_stack.size() >= max_template_nesting)
return TEMPLATE_NESTING_OVERFLOW; return TEMPLATE_NESTING_OVERFLOW;
regex_stack.push(yytext[0]); // special meaning only outside of a character class
if (regex_stack.empty() or regex_stack.top() != '[')
regex_stack.push(yytext[0]);
ECHO; ECHO;
return EOS; return EOS;
} }
JSTokenizer::JSRet JSTokenizer::literal_regex_g_close() JSTokenizer::JSRet JSTokenizer::literal_regex_g_close()
{ {
char c_close = yytext[0];
if (regex_stack.empty()) if (regex_stack.empty())
{ {
// a raw bracket is allowed in regex w/o unicode flag,
// but the parser will accept a bracket in regex with unicode flag
if (c_close == ']')
{
ECHO;
return EOS;
}
debug_logf(5, http_trace, TRACE_JS_PROC, nullptr, debug_logf(5, http_trace, TRACE_JS_PROC, nullptr,
"no group to close, .. %c\n", yytext[0]); "no group to close, .. %c\n", yytext[0]);
return BAD_TOKEN; return BAD_TOKEN;
} }
char c = yytext[0]; char c_open = regex_stack.top();
char o = regex_stack.top(); bool mismatch = false;
char d = o == '(' ? 1 : 2;
switch (c_open)
{
case '(':
mismatch = c_close != ')';
regex_stack.pop();
break;
case '[':
// only the closing bracket has an effect in a character set
if (c_close == ']')
regex_stack.pop();
break;
case '{':
mismatch = c_close != '}';
regex_stack.pop();
break;
regex_stack.pop(); default:
assert(false);
mismatch = true;
}
if (o + d != c) if (mismatch)
{ {
debug_logf(5, http_trace, TRACE_JS_PROC, nullptr, debug_logf(5, http_trace, TRACE_JS_PROC, nullptr,
"closing symbol mismatch, %c .. %c\n", o, c); "closing symbol mismatch, %c .. %c\n", c_open, c_close);
return BAD_TOKEN; return BAD_TOKEN;
} }
ECHO; ECHO;
return EOS; return EOS;
} }
void JSTokenizer::div_assignment_operator() void JSTokenizer::div_assignment_operator()
{ {
skipping to change at line 2771 skipping to change at line 2798
process_punctuator(OPERATOR_ASSIGNMENT); process_punctuator(OPERATOR_ASSIGNMENT);
set_ident_norm(true); set_ident_norm(true);
} }
JSTokenizer::JSRet JSTokenizer::operator_prefix() JSTokenizer::JSRet JSTokenizer::operator_prefix()
{ {
dealias_prefix_reset(); dealias_prefix_reset();
EXEC(do_semicolon_insertion(ASI_GROUP_6)) EXEC(do_semicolon_insertion(ASI_GROUP_6))
EXEC(do_operator_spacing()) EXEC(do_operator_spacing())
ECHO; ECHO;
BEGIN(divop); BEGIN(regst);
set_ident_norm(true); set_ident_norm(true);
return EOS; return EOS;
} }
JSTokenizer::JSRet JSTokenizer::operator_incr_decr() JSTokenizer::JSRet JSTokenizer::operator_incr_decr()
{ {
dealias_increment(); dealias_increment();
dealias_reset(); dealias_reset();
EXEC(do_semicolon_insertion(ASI_GROUP_8)) EXEC(do_semicolon_insertion(ASI_GROUP_8))
EXEC(do_operator_spacing()) EXEC(do_operator_spacing())
skipping to change at line 2795 skipping to change at line 2822
return EOS; return EOS;
} }
JSTokenizer::JSRet JSTokenizer::general_operator() JSTokenizer::JSRet JSTokenizer::general_operator()
{ {
dealias_clear_mutated(false); dealias_clear_mutated(false);
previous_group = ASI_OTHER; previous_group = ASI_OTHER;
dealias_prefix_reset(); dealias_prefix_reset();
EXEC(do_operator_spacing()) EXEC(do_operator_spacing())
ECHO; ECHO;
BEGIN(divop); BEGIN(regst);
set_ident_norm(true); set_ident_norm(true);
return EOS; return EOS;
} }
JSTokenizer::JSRet JSTokenizer::general_literal() JSTokenizer::JSRet JSTokenizer::general_literal()
{ {
dealias_clear_mutated(false); dealias_clear_mutated(false);
dealias_append(); dealias_append();
EXEC(do_semicolon_insertion(ASI_GROUP_7)) EXEC(do_semicolon_insertion(ASI_GROUP_7))
EXEC(do_spacing(LITERAL)) EXEC(do_spacing(LITERAL))
skipping to change at line 2839 skipping to change at line 2866
void JSTokenizer::general_unicode() void JSTokenizer::general_unicode()
{ {
previous_group = ASI_OTHER; previous_group = ASI_OTHER;
ECHO; ECHO;
token = UNDEFINED; token = UNDEFINED;
BEGIN(INITIAL); BEGIN(INITIAL);
set_ident_norm(true); set_ident_norm(true);
} }
void JSTokenizer::escaped_unicode() void JSTokenizer::escaped_unicode_latin_1()
{
// truncate escape symbol, get hex number only
std::string code(YYText() + 2);
yyout << (char)std::stoi(code, nullptr, 16);
}
void JSTokenizer::escaped_unicode_utf_8()
{ {
// truncate escape symbol, get hex number only // truncate escape symbol, get hex number only
std::string code(YYText() + 2); std::string code(YYText() + 2);
yyout << unicode_to_utf8(std::stoi(code, nullptr, 16)); yyout << unicode_to_utf8(std::stoi(code, nullptr, 16));
} }
void JSTokenizer::escaped_code_point() void JSTokenizer::escaped_code_point()
{ {
// truncate escape symbols, get hex number only // truncate escape symbols, get hex number only
std::string code(YYText() + 3); std::string code(YYText() + 3);
code.resize(code.size() - 1); code.resize(code.size() - 1);
yyout << unicode_to_utf8(std::stoi(code, nullptr, 16)); yyout << unicode_to_utf8(std::stoi(code, nullptr, 16));
} }
void JSTokenizer::escaped_url_sequence() void JSTokenizer::escaped_url_sequence_latin_1()
{ {
// truncate escape symbol, get hex number only // truncate escape symbol, get hex number only
std::string code(YYText() + 1); std::string code(YYText() + 1);
yyout << unicode_to_utf8(std::stoi(code, nullptr, 16)); yyout << (char)std::stoi(code, nullptr, 16);
} }
void JSTokenizer::dec_code_point() void JSTokenizer::dec_code_point()
{ {
std::string code(YYText()); std::string code(YYText());
yyout << unicode_to_utf8(std::stoi(code, nullptr, 10)); yyout << unicode_to_utf8(std::stoi(code, nullptr, 10));
} }
void JSTokenizer::hex_code_point() void JSTokenizer::hex_code_point()
{ {
 End of changes. 40 change blocks. 
83 lines changed or deleted 113 lines changed or added

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