diff options
author | David Kalnischkies <david@kalnischkies.de> | 2020-12-03 10:41:43 +0100 |
---|---|---|
committer | David Kalnischkies <david@kalnischkies.de> | 2021-02-03 17:36:45 +0100 |
commit | 10f13938bbf1474451fadcd62e1c31c4b5f5b3d7 (patch) | |
tree | dcf18bfced7c4447eb5ed212f8026a2df0354335 /test/libapt | |
parent | 03790b071d6a97374a03af36eda5698a143300b0 (diff) |
Fix incorrect base64 encoding due to int promotion
For \xff and friends with the highest bit set and hence being a negative
value on signed char systems the wrong encoding is produced as we run
into undefined behaviour accessing negative array indexes.
We can avoid this problem simply by using an unsigned data type.
Diffstat (limited to 'test/libapt')
-rw-r--r-- | test/libapt/strutil_test.cc | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/test/libapt/strutil_test.cc b/test/libapt/strutil_test.cc index 349946b5f..f101d72cf 100644 --- a/test/libapt/strutil_test.cc +++ b/test/libapt/strutil_test.cc @@ -167,6 +167,10 @@ TEST(StrUtilTest,Base64Encode) EXPECT_EQ("ZS4=", Base64Encode("e.")); EXPECT_EQ("Lg==", Base64Encode(".")); EXPECT_EQ("", Base64Encode("")); + EXPECT_EQ("IA==", Base64Encode("\x20")); + EXPECT_EQ("/w==", Base64Encode("\xff")); + EXPECT_EQ("/A==", Base64Encode("\xfc")); + EXPECT_EQ("//8=", Base64Encode("\xff\xff")); } static void ReadMessagesTestWithNewLine(char const * const nl, char const * const ab) { |