Browse Source

move the base64_decoder for BodyLines into bodyparser.cc where it belongs to.

afl-fuzzing
Roker 3 years ago
parent
commit
665964a92e
3 changed files with 21 additions and 24 deletions
  1. +0
    -18
      src/base64.cc
  2. +0
    -5
      src/base64.hh
  3. +21
    -1
      src/bodyparser.cc

+ 0
- 18
src/base64.cc View File

@ -2,7 +2,6 @@
#include <stdint.h>
#include <stdexcept>
#include "pEpMIME_internal.hh"
#include <pEp/pEp_string.h>
namespace pEpMIME
{
@ -91,22 +90,5 @@ std::string encode(const std::string& input, int line_length, const std::string&
}
char* decode(const pEpMIME::BodyLines& bl, size_t& output_size)
{
size_t out_size = 0;
for(const auto& line : bl)
{
out_size += (line.size()+3)/4 * 3;
}
char* out_string = new_string(nullptr, out_size);
char* out_begin = out_string;
char* out_end = out_string + out_size;
decode_iter( pEpMIME::BodyIterator{bl}, pEpMIME::BodyIterator{}, out_begin, out_end);
output_size = out_begin - out_string;
return out_string;
}
} // end of namespace pEpMIME::base64
} // end of namespace pEpMIME

+ 0
- 5
src/base64.hh View File

@ -22,11 +22,6 @@ template<class InIter, class OutIter, class OutIter2>
void decode_iter(InIter begin, InIter end, OutIter& out, OutIter2 out_end);
// Decodes BodyLines
// Returned string is allocated via pEpEngine's new_string()
// Returns NULL and set 'size' to the illegal character if an illegal character found in string.
//char* decode(const pEpMIME::BodyLines&, size_t& output_size);
/*
// Encodes base64-encoded (binary) 'input', with optional line breaks.
// Returned NUL-terminated string is allocated via alloc_fn().


+ 21
- 1
src/bodyparser.cc View File

@ -1,6 +1,8 @@
#include "bodyparser.hh"
#include "pEpMIME_internal.hh"
#include "rules.hh"
#include "base64.hxx"
#include <pEp/pEp_string.h>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix.hpp>
@ -40,11 +42,29 @@ std::ostream& operator<<(std::ostream& o, const ContentType& ct)
namespace pEpMIME
{
char* base64_decode(const BodyLines& bl, size_t& output_size)
{
size_t out_size = 0;
for(const auto& line : bl)
{
out_size += (line.size()+3)/4 * 3;
}
char* out_string = new_string(nullptr, out_size);
char* out_begin = out_string;
char* out_end = out_string + out_size;
base64::decode_iter( BodyIterator{bl}, BodyIterator{}, out_begin, out_end);
output_size = out_begin - out_string;
return out_string;
}
// Tokens from RFC 2045
Rule token = +( vchar - qi::char_("]()<>@,;:\\\"/?=["));
TRule<NameValue> parameter = token >> '=' >> (token | quoted_string.alias());
TRule<ContentType> content_type = token >> '/' >> token >> *( qi::omit[*cfws] >> ';' >> qi::omit[*cfws] >> parameter);


Loading…
Cancel
Save