#include <errno.h>
#include <fstream>
+#include <sstream>
#include <sys/uio.h>
#include <limits.h>
void buffer::list::decode_base64(buffer::list& e)
{
- bufferptr bp(e.length() * 3 / 4 + 4);
+ bufferptr bp(4 + ((e.length() * 3) / 4));
int l = ceph_unarmor(bp.c_str(), bp.c_str() + bp.length(), e.c_str(), e.c_str() + e.length());
+ if (l < 0) {
+ std::ostringstream oss;
+ oss << "decode_base64: decoding failed:\n";
+ hexdump(oss);
+ throw buffer::malformed_input(oss.str().c_str());
+ }
assert(l <= (int)bp.length());
bp.set_length(l);
push_back(bp);
#include "gtest/gtest.h"
-TEST(CorrectBase64Encoding, StringSimple) {
+TEST(CorrectBase64RoundTrip, StringSimple) {
static const int OUT_LEN = 4096;
const char * const original = "abracadabra";
const char * const correctly_encoded = "YWJyYWNhZGFicmE=";
ASSERT_STREQ(original, out2);
}
-TEST(IncorrectBase64Encoding, StringSimple) {
+TEST(IncorrectBase64Decoding, StringSimple) {
static const int OUT_LEN = 4096;
const char * const bad_encoded = "FAKEBASE64 foo";
char out[OUT_LEN];
int alen = ceph_unarmor(out, out + OUT_LEN, bad_encoded, bad_encoded + strlen(bad_encoded));
ASSERT_LT(alen, 0);
}
+
+TEST(IncorrectBase64Decoding2, StringSimple) {
+ string str("FAKEBASE64 foo");
+ bool failed = false;
+ try {
+ bufferlist bl;
+ bl.append(str);
+
+ bufferlist cl;
+ cl.decode_base64(bl);
+ cl.hexdump(std::cerr);
+ }
+ catch (const buffer::error &err) {
+ failed = true;
+ }
+ ASSERT_EQ(failed, true);
+}
$ cauthtool kring --create-keyring
creating kring
-# TODO fix me
$ cauthtool kring --add-key 'FAKEBASE64 foo'
- *** Caught signal (Segmentation fault) ***
- in thread [0-9a-f]{12} (re)
- ceph version .* (re)
- 1: .* (re)
- 2: .* (re)
- 3: .* (re)
- 4: .* (re)
- 5: .* (re)
- 6: .* (re)
- 7: .* (re)
- 8: .* (re)
- Segmentation fault
- [139]
+ can't decode key 'FAKEBASE64 foo'
+ [1]