Commit fbafa847 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

base64: prevent crash in case of empty input

Change-Id: I2bfbde86083829d553a1f79e1c91aed4b2bedd6f
parent 321f83d8
...@@ -33,6 +33,9 @@ encode(const std::vector<uint8_t>::const_iterator begin, ...@@ -33,6 +33,9 @@ encode(const std::vector<uint8_t>::const_iterator begin,
const std::vector<uint8_t>::const_iterator end) const std::vector<uint8_t>::const_iterator end)
{ {
int input_length = std::distance(begin, end); int input_length = std::distance(begin, end);
if (input_length == 0)
return {};
int output_length = PJ_BASE256_TO_BASE64_LEN(input_length); int output_length = PJ_BASE256_TO_BASE64_LEN(input_length);
std::string out; std::string out;
out.resize(output_length); out.resize(output_length);
...@@ -54,6 +57,9 @@ encode(const std::vector<uint8_t>& dat) ...@@ -54,6 +57,9 @@ encode(const std::vector<uint8_t>& dat)
std::vector<uint8_t> std::vector<uint8_t>
decode(const std::string& str) decode(const std::string& str)
{ {
if (str.empty())
return {};
int output_length = PJ_BASE64_TO_BASE256_LEN(str.length()); int output_length = PJ_BASE64_TO_BASE256_LEN(str.length());
const pj_str_t input(sip_utils::CONST_PJ_STR(str)); const pj_str_t input(sip_utils::CONST_PJ_STR(str));
......
Markdown is supported
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