Fix unhandled exception found via libfuzzer

This commit is contained in:
Jason Turner 2017-07-19 10:09:44 -06:00
parent ea03a5462f
commit cfb2e663d3

View File

@ -1051,23 +1051,30 @@ namespace chaiscript
Char_Parser &operator=(const Char_Parser &) = delete; Char_Parser &operator=(const Char_Parser &) = delete;
~Char_Parser(){ ~Char_Parser(){
if (is_octal) { try {
process_octal(); if (is_octal) {
} process_octal();
}
if (is_hex) { if (is_hex) {
process_hex(); process_hex();
} }
if (is_unicode) { if (is_unicode) {
process_unicode(); process_unicode();
}
} catch (const std::invalid_argument &) {
// escape sequence was invalid somehow, we'll pick this
// up in the next part of parsing
} }
} }
void process_hex() void process_hex()
{ {
auto val = stoll(hex_matches, nullptr, 16); if (!hex_matches.empty()) {
match.push_back(char_type(val)); auto val = stoll(hex_matches, nullptr, 16);
match.push_back(char_type(val));
}
hex_matches.clear(); hex_matches.clear();
is_escaped = false; is_escaped = false;
is_hex = false; is_hex = false;
@ -1076,8 +1083,10 @@ namespace chaiscript
void process_octal() void process_octal()
{ {
auto val = stoll(octal_matches, nullptr, 8); if (!octal_matches.empty()) {
match.push_back(char_type(val)); auto val = stoll(octal_matches, nullptr, 8);
match.push_back(char_type(val));
}
octal_matches.clear(); octal_matches.clear();
is_escaped = false; is_escaped = false;
is_octal = false; is_octal = false;
@ -1086,9 +1095,11 @@ namespace chaiscript
void process_unicode() void process_unicode()
{ {
auto val = stoll(hex_matches, nullptr, 16); if (!hex_matches.empty()) {
hex_matches.clear(); auto val = stoll(hex_matches, nullptr, 16);
match += detail::Char_Parser_Helper<string_type>::str_from_ll(val); hex_matches.clear();
match += detail::Char_Parser_Helper<string_type>::str_from_ll(val);
}
is_escaped = false; is_escaped = false;
is_unicode = false; is_unicode = false;
} }
@ -1254,6 +1265,7 @@ namespace chaiscript
cparser.saw_interpolation_marker = false; cparser.saw_interpolation_marker = false;
} else { } else {
cparser.parse(*s, start.line, start.col, *m_filename); cparser.parse(*s, start.line, start.col, *m_filename);
++s; ++s;
} }
} }