Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
yaml-cpp
Commits
2f899756
Unverified
Commit
2f899756
authored
Oct 21, 2021
by
Robert Sebastian Herlim
Committed by
GitHub
Oct 20, 2021
Browse files
Use static_cast<unsigned char> on DecodeBase64 to prevent SEGV on negative values (#1051)
parent
1713859b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
1 deletion
+15
-1
src/binary.cpp
src/binary.cpp
+1
-1
test/binary_test.cpp
test/binary_test.cpp
+14
-0
No files found.
src/binary.cpp
View file @
2f899756
...
@@ -79,7 +79,7 @@ std::vector<unsigned char> DecodeBase64(const std::string &input) {
...
@@ -79,7 +79,7 @@ std::vector<unsigned char> DecodeBase64(const std::string &input) {
// skip newlines
// skip newlines
continue
;
continue
;
}
}
unsigned
char
d
=
decoding
[
static_cast
<
unsigned
>
(
input
[
i
])];
unsigned
char
d
=
decoding
[
static_cast
<
unsigned
char
>
(
input
[
i
])];
if
(
d
==
255
)
if
(
d
==
255
)
return
ret_type
();
return
ret_type
();
...
...
test/binary_test.cpp
0 → 100644
View file @
2f899756
#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
());
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment