Unverified Commit 2f899756 authored by Robert Sebastian Herlim's avatar Robert Sebastian Herlim Committed by GitHub
Browse files

Use static_cast<unsigned char> on DecodeBase64 to prevent SEGV on negative values (#1051)

parent 1713859b
......@@ -79,7 +79,7 @@ std::vector<unsigned char> DecodeBase64(const std::string &input) {
// skip newlines
continue;
}
unsigned char d = decoding[static_cast<unsigned>(input[i])];
unsigned char d = decoding[static_cast<unsigned char>(input[i])];
if (d == 255)
return ret_type();
......
#include "gtest/gtest.h"
#include <yaml-cpp/binary.h>
TEST(BinaryTest, DecodingSimple) {
std::string input{90, 71, 86, 104, 90, 71, 74, 108, 90, 87, 89, 61};
const std::vector<unsigned char> &result = YAML::DecodeBase64(input);
EXPECT_EQ(std::string(result.begin(), result.end()), "deadbeef");
}
TEST(BinaryTest, DecodingNoCrashOnNegative) {
std::string input{-58, -1, -99, 109};
const std::vector<unsigned char> &result = YAML::DecodeBase64(input);
EXPECT_TRUE(result.empty());
}
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