From ea49151746a2d349ccb3c25e8e41df1e88d59a06 Mon Sep 17 00:00:00 2001 From: David Steele Date: Sat, 24 Oct 2020 13:18:02 -0400 Subject: [PATCH] Replace misuse of bufSize() with bufUsed(). bufSize() should only be used whem checking the total size of the buffer, not how much of it is currently used. In these cases bufUsed() and bufSize() are returning the same value but benign-looking code changes could break this assumption. --- src/common/crypto/cipherBlock.c | 2 +- src/common/io/read.c | 2 +- src/common/type/xml.c | 2 +- src/storage/s3/storage.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/common/crypto/cipherBlock.c b/src/common/crypto/cipherBlock.c index ad0cb0a6f..002d2a1f4 100644 --- a/src/common/crypto/cipherBlock.c +++ b/src/common/crypto/cipherBlock.c @@ -392,7 +392,7 @@ cipherBlockNew(CipherMode mode, CipherType cipherType, const Buffer *pass, const FUNCTION_LOG_END(); ASSERT(pass != NULL); - ASSERT(bufSize(pass) > 0); + ASSERT(bufUsed(pass) > 0); // Init crypto subsystem cryptoInit(); diff --git a/src/common/io/read.c b/src/common/io/read.c index a4709d606..d560be10c 100644 --- a/src/common/io/read.c +++ b/src/common/io/read.c @@ -282,7 +282,7 @@ ioReadLineParam(IoRead *this, bool allowEof) // If the buffer is full then the linefeed (if it exists) is outside the buffer if (bufFull(this->output)) - THROW_FMT(FileReadError, "unable to find line in %zu byte buffer", bufSize(this->output)); + THROW_FMT(FileReadError, "unable to find line in %zu byte buffer", bufUsed(this->output)); if (ioReadEof(this)) { diff --git a/src/common/type/xml.c b/src/common/type/xml.c index ff5146394..3dcbca77e 100644 --- a/src/common/type/xml.c +++ b/src/common/type/xml.c @@ -451,7 +451,7 @@ xmlDocumentNewBuf(const Buffer *buffer) FUNCTION_TEST_END(); ASSERT(buffer != NULL); - ASSERT(bufSize(buffer) > 0); + ASSERT(bufUsed(buffer) > 0); FUNCTION_TEST_RETURN(xmlDocumentNewC(bufPtrConst(buffer), bufUsed(buffer))); } diff --git a/src/storage/s3/storage.c b/src/storage/s3/storage.c index 6ed4636e3..e4d68ca36 100644 --- a/src/storage/s3/storage.c +++ b/src/storage/s3/storage.c @@ -804,7 +804,7 @@ storageS3PathRemoveInternal(StorageS3 *this, HttpRequest *request, XmlDocument * const Buffer *response = httpResponseContent(storageS3ResponseP(request)); // Nothing is returned when there are no errors - if (bufSize(response) > 0) + if (bufUsed(response) > 0) { XmlNodeList *errorList = xmlNodeChildList(xmlDocumentRoot(xmlDocumentNewBuf(response)), S3_XML_TAG_ERROR_STR);