Add a lint for SuccessOrExit without assignment. (#26854)
* Add a lint for SuccessOrExit without assignment.
This is almost always a mistake, since it loses track of the error involved.
* Address review comment.
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index 129a1de..8b6f099 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -215,6 +215,14 @@
run: |
git grep -n 'SuccessOrExit(CHIP_ERROR' -- './*' ':(exclude).github/workflows/lint.yml' && exit 1 || exit 0
+ # git grep exits with 0 if it finds a match, but we want
+ # to fail (exit nonzero) on match. And we want to exclude this file,
+ # to avoid our grep regexp matching itself.
+ - name: Check for use of "SuccessOrExit(something-without-assignment(", which should probably be "SuccessOrExit(err = something("
+ if: always()
+ run: |
+ git grep -n 'SuccessOrExit([^=)]*(' -- './*' ':(exclude).github/workflows/lint.yml' && exit 1 || exit 0
+
- name: Check that our hardcoded SHA for clang-format on ARM mac matches the pigweed SHA.
if: always()
run: |
diff --git a/examples/platform/nxp/se05x/DeviceAttestationSe05xCredsExample_v2.cpp b/examples/platform/nxp/se05x/DeviceAttestationSe05xCredsExample_v2.cpp
index 762c74b..4b8202c 100644
--- a/examples/platform/nxp/se05x/DeviceAttestationSe05xCredsExample_v2.cpp
+++ b/examples/platform/nxp/se05x/DeviceAttestationSe05xCredsExample_v2.cpp
@@ -196,7 +196,7 @@
};
tempBuf[0] = (uint8_t) TLV::TLVElementType::Structure;
- SuccessOrExit(se05xSetCertificate(START_CONTAINER_SE05X_ID, tempBuf, 1));
+ SuccessOrExit(err = se05xSetCertificate(START_CONTAINER_SE05X_ID, tempBuf, 1));
for (int i = 1; i <= NO_OF_DEV_ATTEST_MSG_TAGS_TO_PARSE; i++)
{
@@ -206,6 +206,7 @@
{
continue;
}
+ // TODO: Should this be setting err = tlverr?
SuccessOrExit(tlverr);
// Transient binary object ids starting from location 0x7D300005 (TAG1_ID) to 0x7D30000D (TAG3_VALUE_ID)
@@ -215,35 +216,35 @@
taglen = tagReader.GetLength();
tempBuf[0] = tagReader.GetControlByte();
tempBuf[1] = i;
- SuccessOrExit(se05xSetCertificate(TAG1_ID + (3 /* tag + length + value ids */ * (i - 1)), tempBuf, 2));
+ SuccessOrExit(err = se05xSetCertificate(TAG1_ID + (3 /* tag + length + value ids */ * (i - 1)), tempBuf, 2));
if (taglen > 256)
{
tempBuf[0] = taglen & 0xFF;
tempBuf[1] = (taglen >> 8) & 0xFF;
- SuccessOrExit(se05xSetCertificate(TAG1_LEN_ID + (3 * (i - 1)), tempBuf, 2));
+ SuccessOrExit(err = se05xSetCertificate(TAG1_LEN_ID + (3 * (i - 1)), tempBuf, 2));
}
else
{
tempBuf[0] = taglen;
- SuccessOrExit(se05xSetCertificate(TAG1_LEN_ID + (3 * (i - 1)), tempBuf, 1));
+ SuccessOrExit(err = se05xSetCertificate(TAG1_LEN_ID + (3 * (i - 1)), tempBuf, 1));
}
if (taglen > 0)
{
- SuccessOrExit(tagReader.Get(tagvalue));
- SuccessOrExit(se05xSetCertificate(TAG1_VALUE_ID + (3 * (i - 1)), tagvalue.data(), taglen));
+ SuccessOrExit(err = tagReader.Get(tagvalue));
+ SuccessOrExit(err = se05xSetCertificate(TAG1_VALUE_ID + (3 * (i - 1)), tagvalue.data(), taglen));
}
}
tempBuf[0] = (uint8_t) TLV::TLVElementType::EndOfContainer;
- SuccessOrExit(se05xSetCertificate(END_CONTAINER_SE05X_ID, tempBuf, 1));
+ SuccessOrExit(err = se05xSetCertificate(END_CONTAINER_SE05X_ID, tempBuf, 1));
if ((tagReader.GetRemainingLength() + 1 /* End container */) >= 16)
{
/* Set attestation challenge */
- SuccessOrExit(se05xSetCertificate(ATTEST_CHALLENGE_ID, (message_to_sign.end() - 16), 16));
+ SuccessOrExit(err = se05xSetCertificate(ATTEST_CHALLENGE_ID, (message_to_sign.end() - 16), 16));
}
- SuccessOrExit(se05xPerformInternalSign(DEV_ATTESTATION_KEY_SE05X_ID_IS, signature_se05x, &signature_se05x_len));
+ SuccessOrExit(err = se05xPerformInternalSign(DEV_ATTESTATION_KEY_SE05X_ID_IS, signature_se05x, &signature_se05x_len));
err = chip::Crypto::EcdsaAsn1SignatureToRaw(chip::Crypto::kP256_FE_Length, ByteSpan{ signature_se05x, signature_se05x_len },
out_signature_buffer);
diff --git a/src/access/AccessControl.cpp b/src/access/AccessControl.cpp
index 20b58ee..5de6142 100644
--- a/src/access/AccessControl.cpp
+++ b/src/access/AccessControl.cpp
@@ -555,11 +555,12 @@
size_t subjectCount = 0;
size_t targetCount = 0;
- SuccessOrExit(entry.GetAuthMode(authMode));
- SuccessOrExit(entry.GetFabricIndex(fabricIndex));
- SuccessOrExit(entry.GetPrivilege(privilege));
- SuccessOrExit(entry.GetSubjectCount(subjectCount));
- SuccessOrExit(entry.GetTargetCount(targetCount));
+ CHIP_ERROR err = CHIP_NO_ERROR;
+ SuccessOrExit(err = entry.GetAuthMode(authMode));
+ SuccessOrExit(err = entry.GetFabricIndex(fabricIndex));
+ SuccessOrExit(err = entry.GetPrivilege(privilege));
+ SuccessOrExit(err = entry.GetSubjectCount(subjectCount));
+ SuccessOrExit(err = entry.GetTargetCount(targetCount));
#if CHIP_CONFIG_ACCESS_CONTROL_POLICY_LOGGING_VERBOSITY > 1
ChipLogProgress(DataManagement, "AccessControl: validating f=%u p=%c a=%c s=%d t=%d", fabricIndex,
@@ -582,7 +583,7 @@
for (size_t i = 0; i < subjectCount; ++i)
{
NodeId subject;
- SuccessOrExit(entry.GetSubject(i, subject));
+ SuccessOrExit(err = entry.GetSubject(i, subject));
const bool kIsCase = authMode == AuthMode::kCase;
const bool kIsGroup = authMode == AuthMode::kGroup;
#if CHIP_CONFIG_ACCESS_CONTROL_POLICY_LOGGING_VERBOSITY > 1
@@ -594,7 +595,7 @@
for (size_t i = 0; i < targetCount; ++i)
{
Entry::Target target;
- SuccessOrExit(entry.GetTarget(i, target));
+ SuccessOrExit(err = entry.GetTarget(i, target));
const bool kHasCluster = target.flags & Entry::Target::kCluster;
const bool kHasEndpoint = target.flags & Entry::Target::kEndpoint;
const bool kHasDeviceType = target.flags & Entry::Target::kDeviceType;
@@ -608,7 +609,14 @@
return true;
exit:
- ChipLogError(DataManagement, "AccessControl: %s", log);
+ if (err != CHIP_NO_ERROR)
+ {
+ ChipLogError(DataManagement, "AccessControl: %s %" CHIP_ERROR_FORMAT, log, err.Format());
+ }
+ else
+ {
+ ChipLogError(DataManagement, "AccessControl: %s", log);
+ }
return false;
}
diff --git a/src/app/CommandHandler.cpp b/src/app/CommandHandler.cpp
index 6444a2f..3fd99e9 100644
--- a/src/app/CommandHandler.cpp
+++ b/src/app/CommandHandler.cpp
@@ -326,7 +326,7 @@
{
ChipLogDetail(DataManagement, "Received command for Endpoint=%u Cluster=" ChipLogFormatMEI " Command=" ChipLogFormatMEI,
concretePath.mEndpointId, ChipLogValueMEI(concretePath.mClusterId), ChipLogValueMEI(concretePath.mCommandId));
- SuccessOrExit(MatterPreCommandReceivedCallback(concretePath, GetSubjectDescriptor()));
+ SuccessOrExit(err = MatterPreCommandReceivedCallback(concretePath, GetSubjectDescriptor()));
mpCallback->DispatchCommand(*this, concretePath, commandDataReader);
MatterPostCommandReceivedCallback(concretePath, GetSubjectDescriptor());
}
diff --git a/src/app/WriteClient.cpp b/src/app/WriteClient.cpp
index 6f47d40..3391fd6 100644
--- a/src/app/WriteClient.cpp
+++ b/src/app/WriteClient.cpp
@@ -460,7 +460,7 @@
if (!mChunks.IsNull())
{
// Send the next chunk.
- SuccessOrExit(SendWriteRequest());
+ SuccessOrExit(err = SendWriteRequest());
}
}
else if (aPayloadHeader.HasMessageType(MsgType::StatusResponse))
diff --git a/src/app/reporting/Engine.cpp b/src/app/reporting/Engine.cpp
index 89c09e6..757f321 100644
--- a/src/app/reporting/Engine.cpp
+++ b/src/app/reporting/Engine.cpp
@@ -529,7 +529,7 @@
}
}
- SuccessOrExit(reportDataBuilder.GetError());
+ SuccessOrExit(err = reportDataBuilder.GetError());
SuccessOrExit(err = reportDataWriter.UnreserveBuffer(kReservedSizeForMoreChunksFlag + kReservedSizeForIMRevision +
kReservedSizeForEndOfReportMessage));
if (hasMoreChunks)
diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp
index c0d3e10..ce355c0 100644
--- a/src/app/server/Server.cpp
+++ b/src/app/server/Server.cpp
@@ -147,7 +147,7 @@
// Set up attribute persistence before we try to bring up the data model
// handler.
- SuccessOrExit(mAttributePersister.Init(mDeviceStorage));
+ SuccessOrExit(err = mAttributePersister.Init(mDeviceStorage));
SetAttributePersistenceProvider(&mAttributePersister);
{
diff --git a/src/app/tests/integration/chip_im_initiator.cpp b/src/app/tests/integration/chip_im_initiator.cpp
index 3f82262..bbc6505 100644
--- a/src/app/tests/integration/chip_im_initiator.cpp
+++ b/src/app/tests/integration/chip_im_initiator.cpp
@@ -347,7 +347,7 @@
chip::Platform::MakeUnique<chip::app::ReadClient>(chip::app::InteractionModelEngine::GetInstance(), &gExchangeManager,
gMockDelegate, chip::app::ReadClient::InteractionType::Read);
- SuccessOrExit(readClient->SendRequest(readPrepareParams));
+ SuccessOrExit(err = readClient->SendRequest(readPrepareParams));
gMockDelegate.AdoptReadClient(std::move(readClient));
diff --git a/src/controller/java/AndroidCommissioningWindowOpener.cpp b/src/controller/java/AndroidCommissioningWindowOpener.cpp
index a1b9d88..6679887 100644
--- a/src/controller/java/AndroidCommissioningWindowOpener.cpp
+++ b/src/controller/java/AndroidCommissioningWindowOpener.cpp
@@ -121,8 +121,8 @@
std::string QRCode;
std::string manualPairingCode;
- SuccessOrExit(ManualSetupPayloadGenerator(payload).payloadDecimalStringRepresentation(manualPairingCode));
- SuccessOrExit(QRCodeSetupPayloadGenerator(payload).payloadBase38Representation(QRCode));
+ SuccessOrExit(status = ManualSetupPayloadGenerator(payload).payloadDecimalStringRepresentation(manualPairingCode));
+ SuccessOrExit(status = QRCodeSetupPayloadGenerator(payload).payloadBase38Representation(QRCode));
if (self->mOnSuccessMethod != nullptr)
{
diff --git a/src/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp
index 297b22a..fd87516 100644
--- a/src/controller/java/CHIPDeviceController-JNI.cpp
+++ b/src/controller/java/CHIPDeviceController-JNI.cpp
@@ -1605,7 +1605,7 @@
VerifyOrExit(device != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
VerifyOrExit(device->GetSecureSession().HasValue(), err = CHIP_ERROR_MISSING_SECURE_SESSION);
VerifyOrExit(attributeList != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT);
- SuccessOrExit(JniReferences::GetInstance().GetListSize(attributeList, listSize));
+ SuccessOrExit(err = JniReferences::GetInstance().GetListSize(attributeList, listSize));
writeClient = Platform::New<app::WriteClient>(device->GetExchangeManager(), callback->GetChunkedWriteCallback(),
timedRequestTimeoutMs != 0 ? Optional<uint16_t>(timedRequestTimeoutMs)
@@ -1757,7 +1757,8 @@
"()Lchip/devicecontroller/model/ChipPathId;", &getClusterIdMethod));
SuccessOrExit(err = JniReferences::GetInstance().FindMethod(env, invokeElement, "getCommandId",
"()Lchip/devicecontroller/model/ChipPathId;", &getCommandIdMethod));
- SuccessOrExit(JniReferences::GetInstance().FindMethod(env, invokeElement, "getTlvByteArray", "()[B", &getTlvByteArrayMethod));
+ SuccessOrExit(
+ err = JniReferences::GetInstance().FindMethod(env, invokeElement, "getTlvByteArray", "()[B", &getTlvByteArrayMethod));
endpointIdObj = env->CallObjectMethod(invokeElement, getEndpointIdMethod);
VerifyOrExit(!env->ExceptionCheck(), err = CHIP_JNI_ERROR_EXCEPTION_THROWN);
diff --git a/src/controller/python/chip/clusters/command.cpp b/src/controller/python/chip/clusters/command.cpp
index 4dfc3fa..468bff5 100644
--- a/src/controller/python/chip/clusters/command.cpp
+++ b/src/controller/python/chip/clusters/command.cpp
@@ -153,7 +153,7 @@
VerifyOrExit(writer != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
reader.Init(payload, length);
reader.Next();
- SuccessOrExit(writer->CopyContainer(TLV::ContextTag(CommandDataIB::Tag::kFields), reader));
+ SuccessOrExit(err = writer->CopyContainer(TLV::ContextTag(CommandDataIB::Tag::kFields), reader));
}
SuccessOrExit(err = sender->FinishCommand(timedRequestTimeoutMs != 0 ? Optional<uint16_t>(timedRequestTimeoutMs)
@@ -197,7 +197,7 @@
VerifyOrExit(writer != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
reader.Init(payload, length);
reader.Next();
- SuccessOrExit(writer->CopyContainer(TLV::ContextTag(CommandDataIB::Tag::kFields), reader));
+ SuccessOrExit(err = writer->CopyContainer(TLV::ContextTag(CommandDataIB::Tag::kFields), reader));
}
SuccessOrExit(err = sender->FinishCommand(Optional<uint16_t>::Missing()));
diff --git a/src/controller/python/chip/internal/CommissionerImpl.cpp b/src/controller/python/chip/internal/CommissionerImpl.cpp
index c95bdaa..7092024 100644
--- a/src/controller/python/chip/internal/CommissionerImpl.cpp
+++ b/src/controller/python/chip/internal/CommissionerImpl.cpp
@@ -183,17 +183,17 @@
commissionerParams.controllerICAC = icacSpan;
commissionerParams.controllerNOC = nocSpan;
- SuccessOrExit(DeviceControllerFactory::GetInstance().Init(factoryParams));
- err = DeviceControllerFactory::GetInstance().SetupCommissioner(commissionerParams, *result);
+ SuccessOrExit(err = DeviceControllerFactory::GetInstance().Init(factoryParams));
+ SuccessOrExit(err = DeviceControllerFactory::GetInstance().SetupCommissioner(commissionerParams, *result));
- SuccessOrExit(result->GetCompressedFabricIdBytes(compressedFabricIdSpan));
+ SuccessOrExit(err = result->GetCompressedFabricIdBytes(compressedFabricIdSpan));
ChipLogProgress(Support, "Setting up group data for Fabric Index %u with Compressed Fabric ID:",
static_cast<unsigned>(result->GetFabricIndex()));
ChipLogByteSpan(Support, compressedFabricIdSpan);
defaultIpk = chip::GroupTesting::DefaultIpkValue::GetDefaultIpk();
- SuccessOrExit(chip::Credentials::SetSingleIpkEpochKey(&gGroupDataProvider, result->GetFabricIndex(), defaultIpk,
- compressedFabricIdSpan));
+ SuccessOrExit(err = chip::Credentials::SetSingleIpkEpochKey(&gGroupDataProvider, result->GetFabricIndex(), defaultIpk,
+ compressedFabricIdSpan));
}
exit:
ChipLogProgress(Controller, "Commissioner initialization status: %s", chip::ErrorStr(err));
diff --git a/src/crypto/CHIPCryptoPALOpenSSL.cpp b/src/crypto/CHIPCryptoPALOpenSSL.cpp
index b997cee..a3321aa 100644
--- a/src/crypto/CHIPCryptoPALOpenSSL.cpp
+++ b/src/crypto/CHIPCryptoPALOpenSSL.cpp
@@ -940,7 +940,7 @@
out_buf_length = (out_secret.Length() == 0) ? out_secret.Capacity() : out_secret.Length();
result = EVP_PKEY_derive(context, out_secret.Bytes(), &out_buf_length);
VerifyOrExit(result == 1, error = CHIP_ERROR_INTERNAL);
- SuccessOrExit(out_secret.SetLength(out_buf_length));
+ SuccessOrExit(error = out_secret.SetLength(out_buf_length));
exit:
if (ec_key != nullptr)
diff --git a/src/crypto/CHIPCryptoPALPSA.cpp b/src/crypto/CHIPCryptoPALPSA.cpp
index b4dfdf9..1d4a4e2 100644
--- a/src/crypto/CHIPCryptoPALPSA.cpp
+++ b/src/crypto/CHIPCryptoPALPSA.cpp
@@ -589,7 +589,7 @@
status = psa_raw_key_agreement(PSA_ALG_ECDH, context.key_id, remote_public_key.ConstBytes(), remote_public_key.Length(),
out_secret.Bytes(), outputSize, &outputLength);
VerifyOrExit(status == PSA_SUCCESS, error = CHIP_ERROR_INTERNAL);
- SuccessOrExit(out_secret.SetLength(outputLength));
+ SuccessOrExit(error = out_secret.SetLength(outputLength));
exit:
logPsaError(status);
@@ -1420,7 +1420,9 @@
error = CHIP_ERROR_CERT_NOT_TRUSTED;
break;
default:
- SuccessOrExit((result = CertificateChainValidationResult::kInternalFrameworkError, error = CHIP_ERROR_INTERNAL));
+ result = CertificateChainValidationResult::kInternalFrameworkError;
+ error = CHIP_ERROR_INTERNAL;
+ break;
}
exit:
diff --git a/src/crypto/CHIPCryptoPALmbedTLS.cpp b/src/crypto/CHIPCryptoPALmbedTLS.cpp
index 0865d46..26a0015 100644
--- a/src/crypto/CHIPCryptoPALmbedTLS.cpp
+++ b/src/crypto/CHIPCryptoPALmbedTLS.cpp
@@ -653,7 +653,7 @@
result = mbedtls_mpi_write_binary(&mpi_secret, out_secret.Bytes(), secret_length);
VerifyOrExit(result == 0, error = CHIP_ERROR_INTERNAL);
- SuccessOrExit(out_secret.SetLength(secret_length));
+ SuccessOrExit(error = out_secret.SetLength(secret_length));
exit:
keypair = nullptr;
@@ -1537,7 +1537,9 @@
error = CHIP_ERROR_CERT_NOT_TRUSTED;
break;
default:
- SuccessOrExit((result = CertificateChainValidationResult::kInternalFrameworkError, error = CHIP_ERROR_INTERNAL));
+ result = CertificateChainValidationResult::kInternalFrameworkError;
+ error = CHIP_ERROR_INTERNAL;
+ break;
}
exit:
diff --git a/src/crypto/hsm/nxp/CHIPCryptoPALHsm_SE05X_P256.cpp b/src/crypto/hsm/nxp/CHIPCryptoPALHsm_SE05X_P256.cpp
index bac1d26..a467f61 100644
--- a/src/crypto/hsm/nxp/CHIPCryptoPALHsm_SE05X_P256.cpp
+++ b/src/crypto/hsm/nxp/CHIPCryptoPALHsm_SE05X_P256.cpp
@@ -190,7 +190,7 @@
error = EcdsaAsn1SignatureToRaw(kP256_FE_Length, ByteSpan{ signature_se05x, signature_se05x_len }, out_raw_sig_span);
SuccessOrExit(error);
- SuccessOrExit(out_signature.SetLength(2 * kP256_FE_Length));
+ SuccessOrExit(error = out_signature.SetLength(2 * kP256_FE_Length));
error = CHIP_NO_ERROR;
exit:
diff --git a/src/platform/Infineon/CYW30739/FactoryDataProvider.cpp b/src/platform/Infineon/CYW30739/FactoryDataProvider.cpp
index 8d12b16..4b7e6ed 100644
--- a/src/platform/Infineon/CYW30739/FactoryDataProvider.cpp
+++ b/src/platform/Infineon/CYW30739/FactoryDataProvider.cpp
@@ -111,8 +111,8 @@
mbedtls_result = mbedtls_ecp_write_key(ecp, private_key.data(), private_key.size());
VerifyOrExit(mbedtls_result == 0, error = CHIP_ERROR_INTERNAL);
- SuccessOrExit(serializedKeypair.SetLength(public_key.size() + private_key.size()));
- SuccessOrExit(keypair.Deserialize(serializedKeypair));
+ SuccessOrExit(error = serializedKeypair.SetLength(public_key.size() + private_key.size()));
+ SuccessOrExit(error = keypair.Deserialize(serializedKeypair));
exit:
if (mbedtls_result != 0)
diff --git a/src/platform/mbed/BLEManagerImpl.cpp b/src/platform/mbed/BLEManagerImpl.cpp
index cf5914a..ef6518d 100644
--- a/src/platform/mbed/BLEManagerImpl.cpp
+++ b/src/platform/mbed/BLEManagerImpl.cpp
@@ -770,7 +770,7 @@
VerifyOrExit(mbed_err == BLE_ERROR_NONE, err = CHIP_ERROR(chip::ChipError::Range::kOS, mbed_err));
dev_id_info.Init();
- SuccessOrExit(ConfigurationMgr().GetBLEDeviceIdentificationInfo(dev_id_info));
+ SuccessOrExit(err = ConfigurationMgr().GetBLEDeviceIdentificationInfo(dev_id_info));
mbed_err = adv_data_builder.setServiceData(
ShortUUID_CHIPoBLEService, mbed::make_Span<const uint8_t>(reinterpret_cast<uint8_t *>(&dev_id_info), sizeof dev_id_info));
VerifyOrExit(mbed_err == BLE_ERROR_NONE, err = CHIP_ERROR(chip::ChipError::Range::kOS, mbed_err));
diff --git a/src/platform/nxp/common/crypto/CHIPCryptoPALTinyCrypt.cpp b/src/platform/nxp/common/crypto/CHIPCryptoPALTinyCrypt.cpp
index b449169..4ad79d2 100644
--- a/src/platform/nxp/common/crypto/CHIPCryptoPALTinyCrypt.cpp
+++ b/src/platform/nxp/common/crypto/CHIPCryptoPALTinyCrypt.cpp
@@ -599,7 +599,7 @@
result = uECC_shared_secret(remote_public_key.ConstBytes() + 1, keypair->private_key, out_secret.Bytes());
VerifyOrExit(result == UECC_SUCCESS, error = CHIP_ERROR_INTERNAL);
- SuccessOrExit(out_secret.SetLength(secret_length));
+ SuccessOrExit(error = out_secret.SetLength(secret_length));
exit:
keypair = nullptr;
@@ -1377,7 +1377,9 @@
error = CHIP_ERROR_CERT_NOT_TRUSTED;
break;
default:
- SuccessOrExit((result = CertificateChainValidationResult::kInternalFrameworkError, error = CHIP_ERROR_INTERNAL));
+ result = CertificateChainValidationResult::kInternalFrameworkError;
+ error = CHIP_ERROR_INTERNAL;
+ break;
}
exit:
diff --git a/src/platform/nxp/k32w/k32w0/crypto/CHIPCryptoPALNXPUltrafastP256.cpp b/src/platform/nxp/k32w/k32w0/crypto/CHIPCryptoPALNXPUltrafastP256.cpp
index 6660105..289296c 100644
--- a/src/platform/nxp/k32w/k32w0/crypto/CHIPCryptoPALNXPUltrafastP256.cpp
+++ b/src/platform/nxp/k32w/k32w0/crypto/CHIPCryptoPALNXPUltrafastP256.cpp
@@ -594,7 +594,7 @@
out_secret.Bytes());
VerifyOrExit(result == gSecEcdhSuccess_c, error = CHIP_ERROR_INTERNAL);
- SuccessOrExit(out_secret.SetLength(secret_length));
+ SuccessOrExit(error = out_secret.SetLength(secret_length));
exit:
keypair = nullptr;
_log_mbedTLS_error(result);
@@ -1347,7 +1347,9 @@
error = CHIP_ERROR_CERT_NOT_TRUSTED;
break;
default:
- SuccessOrExit((result = CertificateChainValidationResult::kInternalFrameworkError, error = CHIP_ERROR_INTERNAL));
+ result = CertificateChainValidationResult::kInternalFrameworkError;
+ error = CHIP_ERROR_INTERNAL;
+ break;
}
exit:
diff --git a/src/platform/silabs/SiWx917/CHIPCryptoPALTinyCrypt.cpp b/src/platform/silabs/SiWx917/CHIPCryptoPALTinyCrypt.cpp
index 2822438..192f691 100644
--- a/src/platform/silabs/SiWx917/CHIPCryptoPALTinyCrypt.cpp
+++ b/src/platform/silabs/SiWx917/CHIPCryptoPALTinyCrypt.cpp
@@ -569,7 +569,7 @@
result = uECC_shared_secret(remote_public_key.ConstBytes() + 1, keypair->private_key, out_secret.Bytes());
VerifyOrExit(result == UECC_SUCCESS, error = CHIP_ERROR_INTERNAL);
- SuccessOrExit(out_secret.SetLength(secret_length));
+ SuccessOrExit(error = out_secret.SetLength(secret_length));
exit:
keypair = nullptr;
@@ -1378,7 +1378,9 @@
error = CHIP_ERROR_CERT_NOT_TRUSTED;
break;
default:
- SuccessOrExit((result = CertificateChainValidationResult::kInternalFrameworkError, error = CHIP_ERROR_INTERNAL));
+ result = CertificateChainValidationResult::kInternalFrameworkError;
+ error = CHIP_ERROR_INTERNAL;
+ break;
}
exit:
diff --git a/src/platform/silabs/efr32/CHIPCryptoPALPsaEfr32.cpp b/src/platform/silabs/efr32/CHIPCryptoPALPsaEfr32.cpp
index f4acdbc..300348e 100644
--- a/src/platform/silabs/efr32/CHIPCryptoPALPsaEfr32.cpp
+++ b/src/platform/silabs/efr32/CHIPCryptoPALPsaEfr32.cpp
@@ -773,7 +773,7 @@
&output_length);
VerifyOrExit(status == PSA_SUCCESS, error = CHIP_ERROR_INTERNAL);
- SuccessOrExit(out_secret.SetLength(output_length));
+ SuccessOrExit(error = out_secret.SetLength(output_length));
exit:
_log_PSA_error(status);
@@ -1698,7 +1698,9 @@
error = CHIP_ERROR_CERT_NOT_TRUSTED;
break;
default:
- SuccessOrExit((result = CertificateChainValidationResult::kInternalFrameworkError, error = CHIP_ERROR_INTERNAL));
+ result = CertificateChainValidationResult::kInternalFrameworkError;
+ error = CHIP_ERROR_INTERNAL;
+ break;
}
exit:
diff --git a/src/platform/silabs/efr32/Efr32PsaOpaqueKeypair.cpp b/src/platform/silabs/efr32/Efr32PsaOpaqueKeypair.cpp
index 7c39026..5eb9f1f 100644
--- a/src/platform/silabs/efr32/Efr32PsaOpaqueKeypair.cpp
+++ b/src/platform/silabs/efr32/Efr32PsaOpaqueKeypair.cpp
@@ -422,7 +422,7 @@
error = Sign(msg, msg_length, out_signature.Bytes(), out_signature.Capacity(), &output_length);
SuccessOrExit(error);
- SuccessOrExit(out_signature.SetLength(output_length));
+ SuccessOrExit(error = out_signature.SetLength(output_length));
exit:
return error;
}
@@ -437,7 +437,7 @@
(out_secret.Length() == 0) ? out_secret.Capacity() : out_secret.Length(), &output_length);
SuccessOrExit(error);
- SuccessOrExit(out_secret.SetLength(output_length));
+ SuccessOrExit(error = out_secret.SetLength(output_length));
exit:
return error;
}
diff --git a/src/protocols/bdx/BdxMessages.cpp b/src/protocols/bdx/BdxMessages.cpp
index 779f592..1db14be 100644
--- a/src/protocols/bdx/BdxMessages.cpp
+++ b/src/protocols/bdx/BdxMessages.cpp
@@ -94,13 +94,13 @@
CHIP_ERROR TransferInit::Parse(System::PacketBufferHandle aBuffer)
{
- CHIP_ERROR err = CHIP_NO_ERROR;
uint8_t proposedTransferCtl;
uint32_t tmpUint32Value = 0; // Used for reading non-wide length and offset fields
uint8_t * bufStart = aBuffer->Start();
Reader bufReader(bufStart, aBuffer->DataLength());
- SuccessOrExit(bufReader.Read8(&proposedTransferCtl).Read8(mRangeCtlFlags.RawStorage()).Read16(&MaxBlockSize).StatusCode());
+ ReturnErrorOnFailure(
+ bufReader.Read8(&proposedTransferCtl).Read8(mRangeCtlFlags.RawStorage()).Read16(&MaxBlockSize).StatusCode());
Version = proposedTransferCtl & kVersionMask;
TransferCtlOptions.SetRaw(static_cast<uint8_t>(proposedTransferCtl & ~kVersionMask));
@@ -110,11 +110,11 @@
{
if (mRangeCtlFlags.Has(RangeControlFlags::kWiderange))
{
- SuccessOrExit(bufReader.Read64(&StartOffset).StatusCode());
+ ReturnErrorOnFailure(bufReader.Read64(&StartOffset).StatusCode());
}
else
{
- SuccessOrExit(bufReader.Read32(&tmpUint32Value).StatusCode());
+ ReturnErrorOnFailure(bufReader.Read32(&tmpUint32Value).StatusCode());
StartOffset = tmpUint32Value;
}
}
@@ -124,18 +124,18 @@
{
if (mRangeCtlFlags.Has(RangeControlFlags::kWiderange))
{
- SuccessOrExit(bufReader.Read64(&MaxLength).StatusCode());
+ ReturnErrorOnFailure(bufReader.Read64(&MaxLength).StatusCode());
}
else
{
- SuccessOrExit(bufReader.Read32(&tmpUint32Value).StatusCode());
+ ReturnErrorOnFailure(bufReader.Read32(&tmpUint32Value).StatusCode());
MaxLength = tmpUint32Value;
}
}
- SuccessOrExit(bufReader.Read16(&FileDesLength).StatusCode());
+ ReturnErrorOnFailure(bufReader.Read16(&FileDesLength).StatusCode());
- VerifyOrExit(bufReader.HasAtLeast(FileDesLength), err = CHIP_ERROR_MESSAGE_INCOMPLETE);
+ VerifyOrReturnError(bufReader.HasAtLeast(FileDesLength), CHIP_ERROR_MESSAGE_INCOMPLETE);
FileDesignator = &bufStart[bufReader.OctetsRead()];
// Rest of message is metadata (could be empty)
@@ -151,12 +151,7 @@
// Retain ownership of the packet buffer so that the FileDesignator and Metadata pointers remain valid.
Buffer = std::move(aBuffer);
-exit:
- if (bufReader.StatusCode() != CHIP_NO_ERROR)
- {
- err = bufReader.StatusCode();
- }
- return err;
+ return CHIP_NO_ERROR;
}
size_t TransferInit::MessageSize() const
@@ -235,12 +230,11 @@
CHIP_ERROR SendAccept::Parse(System::PacketBufferHandle aBuffer)
{
- CHIP_ERROR err = CHIP_NO_ERROR;
uint8_t transferCtl = 0;
uint8_t * bufStart = aBuffer->Start();
Reader bufReader(bufStart, aBuffer->DataLength());
- SuccessOrExit(bufReader.Read8(&transferCtl).Read16(&MaxBlockSize).StatusCode());
+ ReturnErrorOnFailure(bufReader.Read8(&transferCtl).Read16(&MaxBlockSize).StatusCode());
Version = transferCtl & kVersionMask;
@@ -259,12 +253,7 @@
// Retain ownership of the packet buffer so that the Metadata pointer remains valid.
Buffer = std::move(aBuffer);
-exit:
- if (bufReader.StatusCode() != CHIP_NO_ERROR)
- {
- err = bufReader.StatusCode();
- }
- return err;
+ return CHIP_NO_ERROR;
}
size_t SendAccept::MessageSize() const
@@ -349,13 +338,12 @@
CHIP_ERROR ReceiveAccept::Parse(System::PacketBufferHandle aBuffer)
{
- CHIP_ERROR err = CHIP_NO_ERROR;
uint8_t transferCtl = 0;
uint32_t tmpUint32Value = 0; // Used for reading non-wide length and offset fields
uint8_t * bufStart = aBuffer->Start();
Reader bufReader(bufStart, aBuffer->DataLength());
- SuccessOrExit(bufReader.Read8(&transferCtl).Read8(mRangeCtlFlags.RawStorage()).Read16(&MaxBlockSize).StatusCode());
+ ReturnErrorOnFailure(bufReader.Read8(&transferCtl).Read8(mRangeCtlFlags.RawStorage()).Read16(&MaxBlockSize).StatusCode());
Version = transferCtl & kVersionMask;
@@ -367,11 +355,11 @@
{
if (mRangeCtlFlags.Has(RangeControlFlags::kWiderange))
{
- SuccessOrExit(bufReader.Read64(&StartOffset).StatusCode());
+ ReturnErrorOnFailure(bufReader.Read64(&StartOffset).StatusCode());
}
else
{
- SuccessOrExit(bufReader.Read32(&tmpUint32Value).StatusCode());
+ ReturnErrorOnFailure(bufReader.Read32(&tmpUint32Value).StatusCode());
StartOffset = tmpUint32Value;
}
}
@@ -381,11 +369,11 @@
{
if (mRangeCtlFlags.Has(RangeControlFlags::kWiderange))
{
- SuccessOrExit(bufReader.Read64(&Length).StatusCode());
+ ReturnErrorOnFailure(bufReader.Read64(&Length).StatusCode());
}
else
{
- SuccessOrExit(bufReader.Read32(&tmpUint32Value).StatusCode());
+ ReturnErrorOnFailure(bufReader.Read32(&tmpUint32Value).StatusCode());
Length = tmpUint32Value;
}
}
@@ -402,12 +390,7 @@
// Retain ownership of the packet buffer so that the Metadata pointer remains valid.
Buffer = std::move(aBuffer);
-exit:
- if (bufReader.StatusCode() != CHIP_NO_ERROR)
- {
- err = bufReader.StatusCode();
- }
- return err;
+ return CHIP_NO_ERROR;
}
size_t ReceiveAccept::MessageSize() const
@@ -507,11 +490,10 @@
CHIP_ERROR DataBlock::Parse(System::PacketBufferHandle aBuffer)
{
- CHIP_ERROR err = CHIP_NO_ERROR;
uint8_t * bufStart = aBuffer->Start();
Reader bufReader(bufStart, aBuffer->DataLength());
- SuccessOrExit(bufReader.Read32(&BlockCounter).StatusCode());
+ ReturnErrorOnFailure(bufReader.Read32(&BlockCounter).StatusCode());
// Rest of message is data
Data = nullptr;
@@ -525,12 +507,7 @@
// Retain ownership of the packet buffer so that the Data pointer remains valid.
Buffer = std::move(aBuffer);
-exit:
- if (bufReader.StatusCode() != CHIP_NO_ERROR)
- {
- err = bufReader.StatusCode();
- }
- return err;
+ return CHIP_NO_ERROR;
}
size_t DataBlock::MessageSize() const
@@ -586,18 +563,10 @@
CHIP_ERROR BlockQueryWithSkip::Parse(System::PacketBufferHandle aBuffer)
{
- CHIP_ERROR err = CHIP_NO_ERROR;
uint8_t * bufStart = aBuffer->Start();
Reader bufReader(bufStart, aBuffer->DataLength());
- SuccessOrExit(bufReader.Read32(&BlockCounter).StatusCode());
- SuccessOrExit(bufReader.Read64(&BytesToSkip).StatusCode());
-exit:
- if (bufReader.StatusCode() != CHIP_NO_ERROR)
- {
- err = bufReader.StatusCode();
- }
- return err;
+ return bufReader.Read32(&BlockCounter).Read64(&BytesToSkip).StatusCode();
}
size_t BlockQueryWithSkip::MessageSize() const
diff --git a/src/protocols/secure_channel/CASESession.cpp b/src/protocols/secure_channel/CASESession.cpp
index a8b0ac4..b56076a 100644
--- a/src/protocols/secure_channel/CASESession.cpp
+++ b/src/protocols/secure_channel/CASESession.cpp
@@ -2075,7 +2075,7 @@
msgType == Protocols::SecureChannel::MsgType::CASE_Sigma2Resume ||
msgType == Protocols::SecureChannel::MsgType::CASE_Sigma3)
{
- SuccessOrExit(mExchangeCtxt->FlushAcks());
+ SuccessOrExit(err = mExchangeCtxt->FlushAcks());
}
#endif // CHIP_CONFIG_SLOW_CRYPTO
diff --git a/src/protocols/secure_channel/PASESession.cpp b/src/protocols/secure_channel/PASESession.cpp
index 603c7ac..ae81480 100644
--- a/src/protocols/secure_channel/PASESession.cpp
+++ b/src/protocols/secure_channel/PASESession.cpp
@@ -829,7 +829,7 @@
if (msgType == MsgType::PBKDFParamRequest || msgType == MsgType::PBKDFParamResponse || msgType == MsgType::PASE_Pake1 ||
msgType == MsgType::PASE_Pake2 || msgType == MsgType::PASE_Pake3)
{
- SuccessOrExit(mExchangeCtxt->FlushAcks());
+ SuccessOrExit(err = mExchangeCtxt->FlushAcks());
}
#endif // CHIP_CONFIG_SLOW_CRYPTO