Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

base64decode should return immediately if the input is empty #3065

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/futils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static char to_hex(char code) {

/// @brief Convert a hex character to its integer value.
static char from_hex(char ch) {
return isdigit(ch) ? ch - '0' : static_cast<char>(tolower(ch)) - 'a' + 10;
return 0xF & (isdigit(ch) ? ch - '0' : static_cast<char>(tolower(ch)) - 'a' + 10);
}

std::string urlencode(const std::string& str) {
Expand Down Expand Up @@ -168,7 +168,7 @@ int base64encode(const void* data_buf, size_t dataLength, char* result, size_t r
size_t base64decode(const char* in, char* out, size_t out_size) {
size_t result = 0;
size_t input_length = in ? ::strlen(in) : 0;
if (!in || input_length % 4 != 0)
if (!in || input_length % 4 != 0 || input_length == 0)
return result;

auto encoding_table = reinterpret_cast<const unsigned char*>(base64_encode);
Expand Down Expand Up @@ -324,21 +324,26 @@ Uri Uri::Parse(const std::string& uri) {
auto hostEnd = std::find(authEnd, (pathStart != uriEnd) ? pathStart : queryStart,
':'); // check for port

result.Host = std::string(hostStart, hostEnd);
if (hostStart < hostEnd) {
result.Host = std::string(hostStart, hostEnd);
}

// port
if ((hostEnd != uriEnd) && (*hostEnd == ':')) // we have a port
{
++hostEnd;
auto portEnd = (pathStart != uriEnd) ? pathStart : queryStart;
result.Port = std::string(hostEnd, portEnd);
if (hostEnd < portEnd) {
result.Port = std::string(hostEnd, portEnd);
}
}
if (result.Port.empty() && result.Protocol == "http")
result.Port = "80";

// path
if (pathStart != uriEnd)
if (pathStart < queryStart) {
result.Path = std::string(pathStart, queryStart);
}

// query
if (queryStart != uriEnd)
Expand Down
Loading