Browse Source

Yay, it parses sequences of "encoded_word"s corectly. \o/

afl-fuzzing
Roker 3 years ago
parent
commit
088b9d817c
3 changed files with 10 additions and 4 deletions
  1. +1
    -1
      src/parse_address.cc
  2. +5
    -2
      src/rules.cc
  3. +4
    -1
      src/unittest_address.cc

+ 1
- 1
src/parse_address.cc View File

@ -36,7 +36,7 @@ const Rule addr_spec = local_part >> qi::char_('@') >> domain;
const Rule angle_addr = qi::omit[-fws] >> '<' >> addr_spec >> '>' >> qi::omit[-fws];
const TRule<Identity> name_addr = phrase >> angle_addr;
const TRule<Identity> name_addr = -phrase >> angle_addr;
const TRule<Identity> mailbox = qi::hold[ name_addr ] | (qi::attr("") >> addr_spec);
const TRule<Identity> identity_parser = qi::omit[-fws] >> mailbox >> qi::omit[-fws] /* | group */; // Group? ewww... unsupported.


+ 5
- 2
src/rules.cc View File

@ -38,6 +38,7 @@ URule ctext = qi::char_ - qi::char_("()\\"); // contains whitespace and cont
URule ccontent = comment.alias() | qpair | ctext;
Rule comment = qi::lit('(') >> *ccontent >> qi::lit(')');
Rule cfws = (+(fws | comment))[ qi::_val += ' '];
Rule ocfws = (*(fws | comment))[ qi::_val += ' ']; // optional cfws, but always produce a " " on output to separate words
// RFC 2047
TRule<std::string, std::string, std::string, std::string> encoded_word = ( qi::lit("=?")
@ -70,12 +71,14 @@ Rule quoted_string = '"' >> *qcontent >> '"';
// Notes: "atom" has optional whitespaces at beginning and end, that shall _not_ belong to the atom.
// But when combined into "phrase"s, the ws between the words shall be kept. m(
// This changed grammar should handle this braindead requirements:
Rule word = (quoted_string | encoded_word | atom_nows)
Rule encoded_words = (encoded_word % qi::omit[cfws]);
Rule word = (quoted_string | encoded_words | atom_nows)
// [px::ref(std::cerr) << "<<<WORD:“" << qi::_1 << "”.>>>"]
[qi::_val += qi::_1];
; // Note: putting "encoded_word" here is my own interpretation of RFC 2047
Rule phrase = -cfws >> (word >> *( qi::hold[cfws >> word] ));
Rule phrase = -qi::omit[cfws] >> (word >> *( qi::hold[ocfws >> word] ));
; // obs-phrase not supported, yet.
Rule unstructured = *qi::char_; // just everything. :-P // ( *(-ws >> vchar) >> *ws


+ 4
- 1
src/unittest_address.cc View File

@ -24,9 +24,12 @@ const std::vector<TestEntry> testValues =
{"Alice <alice@pep.example>", "Alice", "alice@pep.example"},
{"Alice Wonder <alice@pep.example>", "Alice Wonder", "alice@pep.example"},
{"bob@pep.example", "", "bob@pep.example" },
{"<bob@pep.example>", "", "bob@pep.example" },
{"=?UTF-8?B?TcO2bGxlciDDnGJlcg==?= <moeller@pep-test.ch>", "Möller Über", "moeller@pep-test.ch"},
{"=?iso-8859-1?Q?'M=FFrthe_=C4=DFink'?= <myrthe@pep.lol>", "'Mÿrthe Äßink'", "myrthe@pep.lol" },
// {"\"John Doe\" <\"john doe\"@pep.lol>", "John Doe", "john doe@pep.lol" },
{"A1 A2 \"<Q3>\" \"<Q4>\"\"<Q5>\" =?ISO-8859-1?Q?En=E71?= =?ISO-8859-1?Q?En=E72?= A8 <atom-test@pep.lol>",
"A1 A2 <Q3> <Q4> <Q5> Enç1Enç2 A8", "atom-test@pep.lol" },
{"\"John Doe\" <\"john doe\"@pep.lol>", "John Doe", "john doe@pep.lol" },
};
} // end of anonymous namespace


Loading…
Cancel
Save