Commit c0d5c121 authored by Guillaume Roguez's avatar Guillaume Roguez
Browse files

base64: fix pjsip assert

we got a crash due to invalid output string size given
to pj_base64_encode().

PJSIP base64 functions have an assert that checks differently
arguments validity than the previous implementation.

This patch fixes that using the same computation as done in pjsip.

Change-Id: I6b9b04be2670e817437a162ca453eff1aaa70420
parent e0754fdf
......@@ -32,7 +32,7 @@ encode(const std::vector<uint8_t>::const_iterator begin,
const std::vector<uint8_t>::const_iterator end)
{
int input_length = std::distance(begin, end);
int output_length = 4 * ((input_length + 2) / 3);
int output_length = PJ_BASE256_TO_BASE64_LEN(input_length);
std::string out;
out.resize(output_length);
......@@ -53,7 +53,7 @@ encode(const std::vector<uint8_t>& dat)
std::vector<uint8_t>
decode(const std::string& str)
{
int output_length = str.length() / 4 * 3 + 2;
int output_length = PJ_BASE64_TO_BASE256_LEN(str.length());
pj_str_t input;
pj_strset(&input, (char*) &(*str.begin()), str.length());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment