From 45b479001bed38b13a301e7e149d98705cef9de9 Mon Sep 17 00:00:00 2001 From: Rohit Jadhav <69809379+jadhavrohit924@users.noreply.github.com> Date: Thu, 3 Feb 2022 04:33:41 +0530 Subject: [PATCH] Addressed review comments (#14400) --- src/app/clusters/ota-requestor/OTARequestor.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/app/clusters/ota-requestor/OTARequestor.cpp b/src/app/clusters/ota-requestor/OTARequestor.cpp index 4306721226afc8..4a7fd2d4a367a9 100644 --- a/src/app/clusters/ota-requestor/OTARequestor.cpp +++ b/src/app/clusters/ota-requestor/OTARequestor.cpp @@ -128,7 +128,14 @@ void OTARequestor::OnQueryImageResponse(void * context, const QueryImageResponse ChipLogDetail(SoftwareUpdate, "Update available from %" PRIu32 " to %" PRIu32 " version", requestorCore->mCurrentVersion, update.softwareVersion); MutableByteSpan updateToken(requestorCore->mUpdateTokenBuffer); - CopySpanToMutableSpan(update.updateToken, updateToken); + // This function copies the bytespan to mutablebytespan only if size of mutablebytespan buffer is greater or equal to + // bytespan otherwise we are copying data upto available size. + err = CopySpanToMutableSpan(update.updateToken, updateToken); + if (err == CHIP_ERROR_BUFFER_TOO_SMALL) + { + memset(updateToken.data(), 0, updateToken.size()); + requestorCore->GenerateUpdateToken(); + } requestorCore->mTargetVersion = update.softwareVersion; requestorCore->mUpdateToken = updateToken; @@ -585,8 +592,6 @@ CHIP_ERROR OTARequestor::ExtractUpdateDescription(const QueryImageResponseDecoda update.softwareVersion = response.softwareVersion.Value(); VerifyOrReturnError(response.updateToken.HasValue(), CHIP_ERROR_INVALID_ARGUMENT); - VerifyOrReturnError(response.updateToken.Value().size() >= 8 && response.updateToken.Value().size() <= 32, - CHIP_ERROR_INVALID_ARGUMENT); update.updateToken = response.updateToken.Value(); update.userConsentNeeded = response.userConsentNeeded.ValueOr(false);