mirror of
https://github.com/arun11299/cpp-jwt.git
synced 2025-05-14 16:58:34 +00:00
Fix out of bounds read in base64_decode
This commit is contained in:
parent
64de7b6f1d
commit
8cb5ea3d5e
2 changed files with 15 additions and 1 deletions
|
@ -200,7 +200,7 @@ inline std::string base64_decode(const char* in, size_t len)
|
||||||
|
|
||||||
constexpr static const DMap dmap{};
|
constexpr static const DMap dmap{};
|
||||||
|
|
||||||
while (dmap.at(in[bytes_rem - 1]) == -1) { bytes_rem--; }
|
while (bytes_rem > 0 && dmap.at(in[bytes_rem - 1]) == -1) { bytes_rem--; }
|
||||||
|
|
||||||
while (bytes_rem > 4)
|
while (bytes_rem > 4)
|
||||||
{
|
{
|
||||||
|
|
|
@ -64,6 +64,20 @@ TEST (DecodeTest, DecodeInvalidHeader)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST (DecodeTest, DecodeEmptyHeader)
|
||||||
|
{
|
||||||
|
using namespace jwt::params;
|
||||||
|
|
||||||
|
const char* enc_str =
|
||||||
|
".eyJhdWQiOiJyaWZ0LmlvIiwiZXhwIjoxNTEzODYzMzcxLCJzdWIiOiJub3RoaW5nIG11Y2gifQ.";
|
||||||
|
|
||||||
|
std::error_code ec;
|
||||||
|
auto obj = jwt::decode(enc_str, algorithms({"hs256"}), ec, secret(""), verify(true));
|
||||||
|
ASSERT_TRUE (ec);
|
||||||
|
EXPECT_EQ (ec.value(), static_cast<int>(jwt::DecodeErrc::JsonParseError));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
TEST (DecodeTest, DecodeInvalidPayload)
|
TEST (DecodeTest, DecodeInvalidPayload)
|
||||||
{
|
{
|
||||||
using namespace jwt::params;
|
using namespace jwt::params;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue