Browse Source

move quoted-printable functions in namespace pEpMIME::qp, and have to rename "quoted pair" parser rul from qp to qpair.

afl-fuzzing
Roker 3 years ago
parent
commit
17dde83974
5 changed files with 39 additions and 30 deletions
  1. +5
    -4
      src/quoted_printable.cc
  2. +12
    -4
      src/quoted_printable.hh
  3. +5
    -5
      src/rules.cc
  4. +1
    -1
      src/rules.hh
  5. +16
    -16
      src/unittest_rule.cc

+ 5
- 4
src/quoted_printable.cc View File

@ -2,7 +2,9 @@
#include <stdint.h>
#include <stdexcept>
namespace
namespace pEpMIME
{
namespace qp
{
#define __ (-1) // invalid char -> exception!
@ -40,8 +42,6 @@ namespace
return h2*16u + l2;
}
} // end of anonymous namespace
// decodes "quoted printable"-encoded 'input', throw if illegal character found in string
std::string qp_decode(const std::string& input)
@ -142,4 +142,5 @@ std::string qp_encode(const std::string& input, int line_length, const std::stri
throw "TODO!";
}
} // end of namespace pEpMIME::qp
} // end of namespace pEpMIME

+ 12
- 4
src/quoted_printable.hh View File

@ -3,18 +3,26 @@
#include <string>
namespace pEpMIME
{
namespace qp
{
// Decodes "quoted printable"-encoded 'input', throw std::runtime_error if an illegal character found in string
std::string qp_decode(const std::string& input);
std::string decode(const std::string& input);
// Encodes into "quoted printable" encoding, with optional line breaks
std::string qp_encode(const std::string& input, int line_length=-1, const std::string& delimiter = "\r\n");
std::string encode(const std::string& input, int line_length=-1, const std::string& delimiter = "\r\n");
// For RFC-2047-compliant header fields "quoted printable" differs a bit:
// Decodes "quoted printable"-encoded 'input', throw std::runtime_error if an illegal character found in string
std::string qp_decode_header(const std::string& input);
std::string decode_header(const std::string& input);
// Encodes into "quoted printable" encoding, with optional line breaks after 78 characters
std::string qp_encode_header(const std::string& input);
std::string encode_header(const std::string& input);
} // end of namespace pEpMIME::qp
} // end of namespace pEpMIME
#endif // PEP_MIME_QUOTED_PRINTABLE_HH

+ 5
- 5
src/rules.cc View File

@ -27,15 +27,15 @@ namespace std
namespace pEpMIME {
Rule vchar = qi::char_("!-~"); // U+0021 ... U+007E - visible ASCII chars.
Rule ws = qi::char_("\t ");
Rule qp = qi::lit('\\') >> (vchar | ws); // quoted pair
Rule ws = qi::char_("\t ");
Rule qpair = qi::lit('\\') >> (vchar | ws); // quoted pair
Rule fws = (+qi::char_("\t\n\r "))[ qi::_val += " "]; // collaps multiple whitespaces into one " "
Rule cws = qi::lit("\t\n\r "); // comment ws -> will be thrown away later anyway
// Comments
URule ctext = qi::char_ - qi::char_("()\\"); // contains whitespace and control chars, too!
URule ccontent = comment.alias() | qp | ctext;
URule ccontent = comment.alias() | qpair | ctext;
Rule comment = qi::lit('(') >> *ccontent >> qi::lit(')');
Rule cfws = (+(fws | comment))[ qi::_val += ' '];
@ -46,7 +46,7 @@ TRule<std::string, std::string, std::string, std::string> encoded_word = ( qi::l
>> (
( qi::lit("?B?") >> (*qi::char_("a-zA-Z0-9/=+")) [px::ref(qi::_b) <<= qi::_1][ qi::_c = px::bind(base64::decode, px::cref(qi::_b))] ) // "B" encoding
|
( qi::lit("?Q?") >> (*(qi::char_-'?'))[ px::ref(qi::_b) <<= qi::_1][qi::_c = px::bind(qp_decode_header, qi::_b)] ) // "Q" encoding
( qi::lit("?Q?") >> (*(qi::char_-'?'))[ px::ref(qi::_b) <<= qi::_1][qi::_c = px::bind(qp::decode_header, qi::_b)] ) // "Q" encoding
)
>> qi::lit("?=") )
// [px::ref(std::cerr) << "<INPUT: \"" << qi::_b << "\", OUTPUT: \"" << qi::_c << "\".>\n"]
@ -63,7 +63,7 @@ Rule aspecials = qi::char_("]()<>:;@\\,.\"[");
// Text in quoted strings
Rule qtext = qi::char_ - qi::char_("\\\"");
Rule qcontent = qp | qtext;
Rule qcontent = qpair | qtext;
Rule quoted_string = '"' >> *qcontent >> '"';
// all together


+ 1
- 1
src/rules.hh View File

@ -20,7 +20,7 @@ extern Rule cfws;
extern Rule vchar; // U+0021 ... U+007E - visible ASCII chars.
extern Rule ws;
extern Rule qp; // quoted pair
extern Rule qpair; // quoted pair
extern Rule fws; // folding/collapsed whitespaces
// Comments


+ 16
- 16
src/unittest_rule.cc View File

@ -67,28 +67,28 @@ std::ostream& operator<<(std::ostream& o, const TE_Base* t)
const std::vector<TE_Base*> testValues =
{
TE("", vchar, NONE),
TE(" ", vchar, NONE ),
TE("x", vchar, "x"s ),
TE("", qp, NONE ),
TE("x", qp, NONE ),
TE("\\\"", qp, "\""s ),
TE("\\\\", qp, "\\"s ),
TE("\\Q" , qp, "Q"s ),
TE("", fws, NONE ),
TE(" ", fws, " "s),
TE(" ", fws, " "s),
TE("\r\n\t \n", fws, " "s),
TE(" x ", fws, " "s),
TE("x ", fws, NONE),
TE("" , vchar, NONE ),
TE(" " , vchar, NONE ),
TE("x" , vchar, "x"s ),
TE("" , qpair, NONE ),
TE("x" , qpair, NONE ),
TE("\\\"", qpair, "\""s ),
TE("\\\\", qpair, "\\"s ),
TE("\\Q" , qpair, "Q"s ),
TE("" , fws , NONE ),
TE(" " , fws , " "s ),
TE(" " , fws , " "s ),
TE("\r\n\t \n" , fws, " "s ),
TE(" x " , fws , " "s ),
TE("x " , fws , NONE ),
TE("=?UTF-8?Q?Banane?=", encoded_word, "Banane"s ),
TE("=?UTF-8?Q?=C3=84pfel?=", encoded_word, "Äpfel"s ),
TE("", comment, NONE ),
TE("" , comment, NONE ),
TE("\\", comment, NONE ),
TE("()", comment, ""s ),
TE("(a comment)", comment, ""s ),
TE("(a comment)" , comment, ""s ),
TE("(invalid (x)", comment, NONE ),
TE("(this is (a nested\") comment \\) )", comment, ""s),
TE("(this is (a \"nested) comment \\( )", comment, ""s),


Loading…
Cancel
Save