From 6db69c2b0ac0821673e8f68ead0d1076938c3d1b Mon Sep 17 00:00:00 2001 From: Charles Munson Date: Thu, 24 Mar 2016 16:34:52 +0100 Subject: [PATCH] Consolidate rAssert statements in BlockNameIO Whitespace cleanup StreamNameIO rAssert statements should be the same --- encfs/BlockNameIO.cpp | 9 ++++----- encfs/NameIO.cpp | 8 ++++---- encfs/NameIO.h | 8 ++++---- encfs/NullNameIO.cpp | 2 +- encfs/StreamNameIO.cpp | 3 +-- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/encfs/BlockNameIO.cpp b/encfs/BlockNameIO.cpp index 075ae76..ce189a9 100644 --- a/encfs/BlockNameIO.cpp +++ b/encfs/BlockNameIO.cpp @@ -137,17 +137,16 @@ int BlockNameIO::maxDecodedNameLen(int encodedNameLen) const { int BlockNameIO::encodeName(const char *plaintextName, int length, uint64_t *iv, char *encodedName, int bufferLength) const { - // copy the data into the encoding buffer.. - rAssert(length <= (bufferLength - 2)); - memcpy(encodedName + 2, plaintextName, length); - // Pad encryption buffer to block boundary.. int padding = _bs - length % _bs; if (padding == 0) padding = _bs; // padding a full extra block! - rAssert(padding <= (bufferLength - length - 2)); + rAssert(bufferLength >= length + 2 + padding); memset(encodedName + length + 2, (unsigned char)padding, padding); + // copy the data into the encoding buffer.. + memcpy(encodedName + 2, plaintextName, length); + // store the IV before it is modified by the MAC call. uint64_t tmpIV = 0; if (iv && _interface >= 3) tmpIV = *iv; diff --git a/encfs/NameIO.cpp b/encfs/NameIO.cpp index ebf8c23..a7d8611 100644 --- a/encfs/NameIO.cpp +++ b/encfs/NameIO.cpp @@ -166,10 +166,10 @@ std::string NameIO::recodePath(const char *path, // figure out buffer sizes int approxLen = (this->*_length)(len); if (approxLen <= 0) throw ERROR("Filename too small to decode"); - int bufSize = 0; + int bufSize = 0; BUFFER_INIT_S(codeBuf, 32, (unsigned int)approxLen + 1, bufSize) - + // code the name int codedLen = (this->*_code)(path, len, iv, codeBuf, bufSize); rAssert(codedLen <= approxLen); @@ -231,7 +231,7 @@ std::string NameIO::_encodeName(const char *plaintextName, int length) const { int bufSize = 0; BUFFER_INIT_S(codeBuf, 32, (unsigned int)approxLen + 1, bufSize) - + // code the name int codedLen = encodeName(plaintextName, length, 0, codeBuf, bufSize); rAssert(codedLen <= approxLen); @@ -250,7 +250,7 @@ std::string NameIO::_decodeName(const char *encodedName, int length) const { int bufSize = 0; BUFFER_INIT_S(codeBuf, 32, (unsigned int)approxLen + 1, bufSize) - + // code the name int codedLen = decodeName(encodedName, length, 0, codeBuf, bufSize); rAssert(codedLen <= approxLen); diff --git a/encfs/NameIO.h b/encfs/NameIO.h index 7f7ecb3..726325f 100644 --- a/encfs/NameIO.h +++ b/encfs/NameIO.h @@ -108,11 +108,11 @@ class NameIO { }; /* - Helper macros for creating temporary buffers with an optimization that - below a given size (OptimizedSize) is allocated on the stack, and when a - larger size is requested it is allocated on the heap. + Helper macros for creating temporary buffers with an optimization that + below a given size (OptimizedSize) is allocated on the stack, and when a + larger size is requested it is allocated on the heap. - BUFFER_RESET should be called for the same name as BUFFER_INIT + BUFFER_RESET should be called for the same name as BUFFER_INIT */ #define BUFFER_INIT(Name, OptimizedSize, Size) \ char Name##_Raw[OptimizedSize]; \ diff --git a/encfs/NullNameIO.cpp b/encfs/NullNameIO.cpp index fada7bf..1dbcece 100644 --- a/encfs/NullNameIO.cpp +++ b/encfs/NullNameIO.cpp @@ -58,7 +58,7 @@ int NullNameIO::maxDecodedNameLen(int encodedNameLen) const { int NullNameIO::encodeName(const char *plaintextName, int length, uint64_t *iv, char *encodedName, int bufferLength) const { (void)iv; - + rAssert(length <= bufferLength); memcpy(encodedName, plaintextName, length); diff --git a/encfs/StreamNameIO.cpp b/encfs/StreamNameIO.cpp index a14b00b..17efe36 100644 --- a/encfs/StreamNameIO.cpp +++ b/encfs/StreamNameIO.cpp @@ -99,18 +99,17 @@ int StreamNameIO::encodeName(const char *plaintextName, int length, // add on checksum bytes unsigned char *encodeBegin; + rAssert(bufferLength >= length + 2); if (_interface >= 1) { // current versions store the checksum at the beginning encodedName[0] = (mac >> 8) & 0xff; encodedName[1] = (mac)&0xff; encodeBegin = (unsigned char *)encodedName + 2; - rAssert(length <= (bufferLength - 2)); } else { // encfs 0.x stored checksums at the end. encodedName[length] = (mac >> 8) & 0xff; encodedName[length + 1] = (mac)&0xff; encodeBegin = (unsigned char *)encodedName; - rAssert(length <= bufferLength); } // stream encode the plaintext bytes