Browse Source

handle Non-MIME mail bodies properly: if valid UTF-8 rturn NFC-normalized string. if not, return it as 7-bit ASCII string

afl-fuzzing
Roker 3 years ago
parent
commit
bbf4af18de
1 changed files with 9 additions and 13 deletions
  1. +9
    -13
      src/bodyparser.cc

+ 9
- 13
src/bodyparser.cc View File

@ -4,6 +4,7 @@
#include "base64.hxx"
#include "quoted_printable.hxx"
#include "string_case.hh"
#include "nfc.hh"
#include "to_utf8.hh"
#include <pEp/pEp_string.h>
@ -310,20 +311,15 @@ void parse_body(message* msg, const HeaderSection& headers, const BodyLines& bod
}else{ // Non-MIME mail
std::cerr << "<<< NO_MIME_MAIL >>> " << body.size() << " body lines.\n";
size_t body_size = 0;
for(const auto& line : body)
sv combined_body = combineLines(body);
if(isUtf8(combined_body.data(), combined_body.data()+combined_body.size()) )
{
body_size += line.size() + 2;
}
char* pbody = msg->longmsg = new_string(nullptr, body_size);
for(const auto& line : body)
{
memcpy(pbody, line.data(), line.size());
pbody += line.size();
memcpy(pbody, "\r\n", 2);
pbody += 2;
const std::string& nfc_string = toNFC( std::string(combined_body) ); // FIXME: double copy! :-((
msg->longmsg = new_string(nfc_string.c_str(), nfc_string.size()); // FIXME: 3rd copy! :-(((
}else{
char* pbody = msg->longmsg = new_string(combined_body.data(), combined_body.size());
// no valid UTF-8? Hum, whatever it is, make it 7-bit ASCII for safety.
std::for_each(pbody, pbody+combined_body.size(), [](char& c) { c &= 0x7f; } );
}
}
}


Loading…
Cancel
Save