Browse Source

oops.. msg->opt_fields are not filled, because stringpair_list_add() is strange. Fixed. "Received" headers are discarded explicitly, so they DON'T GO into msg->opt_fields, as desired for privacy reasons.

afl-fuzzing
Roker 3 years ago
parent
commit
aad8fb5c77
2 changed files with 49 additions and 3 deletions
  1. +27
    -2
      src/headerparser.cc
  2. +22
    -1
      src/unittest_mime.cc

+ 27
- 2
src/headerparser.cc View File

@ -45,6 +45,14 @@ struct ParserBase
};
struct Discard : public ParserBase
{
virtual void assign(message* msg, const std::string& s) override
{
// Do nothing, intentionally. So this header is discarded.
}
};
// Parser that assigns the result of the function to the message data member
template<class T>
struct TParser : public ParserBase
@ -130,6 +138,7 @@ const std::map<std::string, struct ParserBase*> parsers =
{"In-Reply-To", P<DS, stringlist_t*>(&message::in_reply_to, message_id_list, &create_stringlist) },
{"References" , P<std::vector<std::string>, stringlist_t*>(&message::references, message_id_list, &create_stringlist) },
{"Received", new Discard },
};
// parses the header and fill the parts in msg
@ -143,9 +152,25 @@ void parse_header(message* msg, const HeaderSection& header)
const auto p = parsers.find( h.name );
if(p == parsers.end())
{
// unknown header with no special parser:
stringpair_list_add( msg->opt_fields, new_stringpair( h.name.c_str(), h.value.c_str() ));
// unknown header with no special parser: just dump it in opt_fields
auto sp = new_stringpair( h.name.c_str(), h.value.c_str() );
auto f = stringpair_list_add( msg->opt_fields, sp);
// the function above has a strange semantic:
// it adds the stringpair to the given list (if it is non-NULL) or returns it (if given list is NULL).
if(f)
{
if(msg->opt_fields == nullptr)
{
msg->opt_fields = f;
}else{
// do nothing. f is already added to the list. oO
}
}else{ // stringpair_list_add() fails for whatever reason: avoid memory leak
free_stringpair(sp);
}
}else{
// do the "right thing" with this well-known header line:
p->second->assign(msg, h.value);
}
}


+ 22
- 1
src/unittest_mime.cc View File

@ -20,6 +20,7 @@ namespace std
}
using namespace std::string_literals;
namespace {
static const char* mail1_eml =
@ -147,7 +148,7 @@ std::string out(stringlist_t* sl)
{
if(sl==nullptr)
{
return "SL[] ";
return "NULL ";
}else{
std::string ret = "SL[";
char* s = sl->value;
@ -163,6 +164,26 @@ std::string out(stringlist_t* sl)
}
std::string out(stringpair_list_t* spl)
{
if(spl==nullptr)
{
return "NULL ";
}else{
std::string ret = "SPL[";
auto sp = spl->value;
ret += ""s + sp->key + "”:“"s + sp->value + "";
while(spl->next)
{
spl = spl->next;
auto sp = spl->value;
ret += ", “"s + sp->key + "”:“"s + sp->value + "";
}
return ret + ']';
}
}
#define PRINT(member) std::cerr << "\t" #member ": " << out(m->member) << "\n"
void print_message(message* m)


Loading…
Cancel
Save