It used to return -EINVAL because it thought the end was not aligned
to 4 bytes.
Clean up superfluous src < end test in if, the while itself guarantees
that.
while (src < end) {
int a, b, c, d;
- if (src < end && src[0] == '\n')
+ if (src[0] == '\n') {
src++;
+ continue;
+ }
+
if (src + 4 > end)
return -EINVAL;
a = decode_bits(src[0]);
}
}
+TEST(EdgeCase, EndsInNewline) {
+ static const int OUT_MAX = 4096;
+
+ char b64[] =
+ "aaaa\n";
+
+ char decoded[OUT_MAX];
+ memset(decoded, 0, sizeof(decoded));
+ int blen = ceph_unarmor(decoded, decoded + OUT_MAX, b64, b64 + sizeof(b64)-1);
+ ASSERT_GE(blen, 0);
+}
+
TEST(FuzzEncoding, BadDecode1) {
static const int OUT_LEN = 4096;
const char * const bad_encoded = "FAKEBASE64 foo";