Skip to content

Commit 83c8608

Browse files
authored
Batch project-chip#14 nodiscard errors: transport, wifipaf (project-chip#41872)
1 parent 21049ed commit 83c8608

File tree

10 files changed

+41
-46
lines changed

10 files changed

+41
-46
lines changed

src/transport/CryptoContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ CHIP_ERROR CryptoContext::PrivacyEncrypt(const uint8_t * input, size_t input_len
273273
ByteSpan plaintext(input, input_length);
274274
MutableByteSpan privacytext(output, input_length);
275275
CryptoContext::NonceStorage privacyNonce;
276-
CryptoContext::BuildPrivacyNonce(privacyNonce, header.GetSessionId(), mac);
276+
ReturnErrorOnFailure(CryptoContext::BuildPrivacyNonce(privacyNonce, header.GetSessionId(), mac));
277277

278278
return mKeyContext->PrivacyEncrypt(plaintext, privacyNonce, privacytext);
279279
}
@@ -291,7 +291,7 @@ CHIP_ERROR CryptoContext::PrivacyDecrypt(const uint8_t * input, size_t input_len
291291
const ByteSpan privacytext(input, input_length);
292292
MutableByteSpan plaintext(output, input_length);
293293
CryptoContext::NonceStorage privacyNonce;
294-
CryptoContext::BuildPrivacyNonce(privacyNonce, header.GetSessionId(), mac);
294+
ReturnErrorOnFailure(CryptoContext::BuildPrivacyNonce(privacyNonce, header.GetSessionId(), mac));
295295

296296
return mKeyContext->PrivacyDecrypt(privacytext, privacyNonce, plaintext);
297297
}

src/transport/GroupPeerMessageCounter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ void GroupPeerTable::RemoveAndCompactFabric(uint32_t tableIndex)
259259

260260
GroupOutgoingCounters::GroupOutgoingCounters(chip::PersistentStorageDelegate * storage_delegate)
261261
{
262-
Init(storage_delegate);
262+
TEMPORARY_RETURN_IGNORED Init(storage_delegate);
263263
}
264264

265265
CHIP_ERROR GroupOutgoingCounters::Init(chip::PersistentStorageDelegate * storage_delegate)

src/transport/SessionManager.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ void SessionManager::Shutdown()
167167
*/
168168
void SessionManager::FabricRemoved(FabricIndex fabricIndex)
169169
{
170-
gGroupPeerTable->FabricRemoved(fabricIndex);
170+
TEMPORARY_RETURN_IGNORED gGroupPeerTable->FabricRemoved(fabricIndex);
171171
}
172172

173173
CHIP_ERROR SessionManager::PrepareMessage(const SessionHandle & sessionHandle, PayloadHeader & payloadHeader,
@@ -211,7 +211,7 @@ CHIP_ERROR SessionManager::PrepareMessage(const SessionHandle & sessionHandle, P
211211

212212
packetHeader.SetDestinationGroupId(groupSession->GetGroupId());
213213
packetHeader.SetMessageCounter(mGroupClientCounter.GetCounter(isControlMsg));
214-
mGroupClientCounter.IncrementCounter(isControlMsg);
214+
TEMPORARY_RETURN_IGNORED mGroupClientCounter.IncrementCounter(isControlMsg);
215215
packetHeader.SetSessionType(Header::SessionType::kGroupSession);
216216
sourceNodeId = fabric->GetNodeId();
217217
packetHeader.SetSourceNodeId(sourceNodeId);
@@ -238,7 +238,8 @@ CHIP_ERROR SessionManager::PrepareMessage(const SessionHandle & sessionHandle, P
238238
CHIP_TRACE_MESSAGE_SENT(payloadHeader, packetHeader, destination_address, message->Start(), message->TotalLength());
239239

240240
CryptoContext::NonceStorage nonce;
241-
CryptoContext::BuildNonce(nonce, packetHeader.GetSecurityFlags(), packetHeader.GetMessageCounter(), sourceNodeId);
241+
ReturnErrorOnFailure(
242+
CryptoContext::BuildNonce(nonce, packetHeader.GetSecurityFlags(), packetHeader.GetMessageCounter(), sourceNodeId));
242243
CHIP_ERROR err = SecureMessageCodec::Encrypt(cryptoContext, nonce, payloadHeader, packetHeader, message);
243244
keyContext->Release();
244245
ReturnErrorOnFailure(err);
@@ -277,7 +278,7 @@ CHIP_ERROR SessionManager::PrepareMessage(const SessionHandle & sessionHandle, P
277278

278279
CryptoContext::NonceStorage nonce;
279280
sourceNodeId = session->GetLocalScopedNodeId().GetNodeId();
280-
CryptoContext::BuildNonce(nonce, packetHeader.GetSecurityFlags(), messageCounter, sourceNodeId);
281+
ReturnErrorOnFailure(CryptoContext::BuildNonce(nonce, packetHeader.GetSecurityFlags(), messageCounter, sourceNodeId));
281282

282283
ReturnErrorOnFailure(SecureMessageCodec::Encrypt(cryptoContext, nonce, payloadHeader, packetHeader, message));
283284

@@ -454,10 +455,10 @@ CHIP_ERROR SessionManager::SendPreparedMessage(const SessionHandle & sessionHand
454455

455456
while (interfaceIt.Next())
456457
{
457-
char name[Inet::InterfaceId::kMaxIfNameLength];
458-
interfaceIt.GetInterfaceName(name, Inet::InterfaceId::kMaxIfNameLength);
459458
if (interfaceIt.SupportsMulticast() && interfaceIt.IsUp())
460459
{
460+
char name[Inet::InterfaceId::kMaxIfNameLength];
461+
TEMPORARY_RETURN_IGNORED interfaceIt.GetInterfaceName(name, Inet::InterfaceId::kMaxIfNameLength);
461462
interfaceId = interfaceIt.GetInterfaceId();
462463
if (CHIP_NO_ERROR == interfaceId.GetLinkLocalAddr(&addr))
463464
{
@@ -946,10 +947,11 @@ void SessionManager::SecureUnicastMessageDispatch(const PacketHeader & partialPa
946947
CryptoContext::NonceStorage nonce;
947948
// PASE Sessions use the undefined node ID of all zeroes, since there is no node ID to use
948949
// and the key is short-lived and always different for each PASE session.
949-
CryptoContext::BuildNonce(nonce, packetHeader.GetSecurityFlags(), packetHeader.GetMessageCounter(),
950-
secureSession->GetSecureSessionType() == SecureSession::Type::kCASE ? secureSession->GetPeerNodeId()
951-
: kUndefinedNodeId);
952-
if (SecureMessageCodec::Decrypt(secureSession->GetCryptoContext(), nonce, payloadHeader, packetHeader, msg) != CHIP_NO_ERROR)
950+
CHIP_ERROR nonceResult = CryptoContext::BuildNonce(
951+
nonce, packetHeader.GetSecurityFlags(), packetHeader.GetMessageCounter(),
952+
secureSession->GetSecureSessionType() == SecureSession::Type::kCASE ? secureSession->GetPeerNodeId() : kUndefinedNodeId);
953+
if ((nonceResult != CHIP_NO_ERROR) ||
954+
SecureMessageCodec::Decrypt(secureSession->GetCryptoContext(), nonce, payloadHeader, packetHeader, msg) != CHIP_NO_ERROR)
953955
{
954956
ChipLogError(Inet, "Secure transport received message, but failed to decode/authenticate it, discarding");
955957
return;
@@ -1056,9 +1058,11 @@ static bool GroupKeyDecryptAttempt(const PacketHeader & partialPacketHeader, Pac
10561058
}
10571059

10581060
CryptoContext::NonceStorage nonce;
1059-
CryptoContext::BuildNonce(nonce, packetHeaderCopy.GetSecurityFlags(), packetHeaderCopy.GetMessageCounter(),
1060-
packetHeaderCopy.GetSourceNodeId().Value());
1061-
decrypted = (CHIP_NO_ERROR == SecureMessageCodec::Decrypt(context, nonce, payloadHeader, packetHeaderCopy, msgCopy));
1061+
CHIP_ERROR nonceResult =
1062+
CryptoContext::BuildNonce(nonce, packetHeaderCopy.GetSecurityFlags(), packetHeaderCopy.GetMessageCounter(),
1063+
packetHeaderCopy.GetSourceNodeId().Value());
1064+
decrypted = (nonceResult == CHIP_NO_ERROR) &&
1065+
(CHIP_NO_ERROR == SecureMessageCodec::Decrypt(context, nonce, payloadHeader, packetHeaderCopy, msgCopy));
10621066

10631067
return decrypted;
10641068
}

src/transport/SessionManager.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,7 @@ class DLL_EXPORT SessionManager : public TransportMgrDelegate, public FabricTabl
312312
auto * targetFabric = mFabricTable->FindFabricWithIndex(fabricIndex);
313313
VerifyOrReturnError(targetFabric != nullptr, CHIP_ERROR_INVALID_FABRIC_INDEX);
314314

315-
auto err = targetFabric->FetchRootPubkey(targetPubKey);
316-
VerifyOrDie(err == CHIP_NO_ERROR);
315+
SuccessOrDie(targetFabric->FetchRootPubkey(targetPubKey));
317316

318317
mSecureSessions.ForEachSession([&](auto * session) {
319318
Crypto::P256PublicKey comparePubKey;
@@ -331,8 +330,7 @@ class DLL_EXPORT SessionManager : public TransportMgrDelegate, public FabricTabl
331330
auto * compareFabric = mFabricTable->FindFabricWithIndex(session->GetFabricIndex());
332331
VerifyOrDie(compareFabric != nullptr);
333332

334-
err = compareFabric->FetchRootPubkey(comparePubKey);
335-
VerifyOrDie(err == CHIP_NO_ERROR);
333+
SuccessOrDie(compareFabric->FetchRootPubkey(comparePubKey));
336334

337335
if (comparePubKey.Matches(targetPubKey) && targetFabric->GetFabricId() == compareFabric->GetFabricId())
338336
{

src/transport/raw/BLE.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void BLEBase::ClearState()
4545
{
4646
if (mBleLayer)
4747
{
48-
mBleLayer->CancelBleIncompleteConnection();
48+
TEMPORARY_RETURN_IGNORED mBleLayer->CancelBleIncompleteConnection();
4949
mBleLayer->mBleTransport = nullptr;
5050
mBleLayer = nullptr;
5151
}

src/transport/raw/NFC.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,7 @@ CHIP_ERROR NFCBase::SendMessage(const Transport::PeerAddress & address, System::
101101
VerifyOrReturnError(address.GetTransportType() == Type::kNfc, CHIP_ERROR_INVALID_ARGUMENT);
102102
VerifyOrReturnError(mState == State::kConnected, CHIP_ERROR_INCORRECT_STATE);
103103

104-
DeviceLayer::Internal::NFCCommissioningMgrImpl().SendToNfcTag(address, std::move(msgBuf));
105-
106-
return CHIP_NO_ERROR;
104+
return DeviceLayer::Internal::NFCCommissioningMgrImpl().SendToNfcTag(address, std::move(msgBuf));
107105
}
108106

109107
} // namespace Transport

src/transport/raw/TCP.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,8 @@ void TCPBase::HandleTCPEndPointConnectComplete(const Inet::TCPEndPointHandle & e
591591
});
592592

593593
// Set the TCPKeepalive configurations on the established connection
594-
endPoint->EnableKeepAlive(activeConnection->mTCPKeepAliveIntervalSecs, activeConnection->mTCPMaxNumKeepAliveProbes);
594+
TEMPORARY_RETURN_IGNORED endPoint->EnableKeepAlive(activeConnection->mTCPKeepAliveIntervalSecs,
595+
activeConnection->mTCPMaxNumKeepAliveProbes);
595596

596597
ChipLogProgress(Inet, "Connection established successfully with %s.", addrStr);
597598

@@ -655,13 +656,16 @@ CHIP_ERROR TCPBase::DoHandleIncomingConnection(const Inet::TCPEndPointHandle & l
655656
endPoint->OnConnectionClosed = HandleTCPEndPointConnectionClosed;
656657

657658
// By default, disable TCP Nagle buffering by setting TCP_NODELAY socket option to true
658-
endPoint->EnableNoDelay();
659+
// If it fails, we can still use the connection
660+
RETURN_SAFELY_IGNORED endPoint->EnableNoDelay();
659661

660662
mUsedEndPointCount++;
661663
activeConnection->mConnectionState = TCPState::kConnected;
662664

663665
// Set the TCPKeepalive configurations on the received connection
664-
endPoint->EnableKeepAlive(activeConnection->mTCPKeepAliveIntervalSecs, activeConnection->mTCPMaxNumKeepAliveProbes);
666+
// If it fails, we can still use the connection until it dies
667+
RETURN_SAFELY_IGNORED endPoint->EnableKeepAlive(activeConnection->mTCPKeepAliveIntervalSecs,
668+
activeConnection->mTCPMaxNumKeepAliveProbes);
665669

666670
char addrStr[Transport::PeerAddress::kMaxToStringSize];
667671
peerAddress.ToString(addrStr);

src/transport/raw/WiFiPAF.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ CHIP_ERROR WiFiPAFBase::SendMessage(const Transport::PeerAddress & address, Pack
5858
ChipLogError(Inet, "WiFi-PAF: No valid session whose nodeId: %lu", address.GetRemoteId());
5959
return CHIP_ERROR_INCORRECT_STATE;
6060
}
61-
mWiFiPAFLayer->SendMessage(*pTxInfo, std::move(msgBuf));
62-
63-
return CHIP_NO_ERROR;
61+
return mWiFiPAFLayer->SendMessage(*pTxInfo, std::move(msgBuf));
6462
}
6563

6664
bool WiFiPAFBase::CanSendToPeer(const Transport::PeerAddress & address)
@@ -106,15 +104,13 @@ CHIP_ERROR WiFiPAFBase::WiFiPAFMessageReceived(WiFiPAFSession & RxInfo, PacketBu
106104
CHIP_ERROR WiFiPAFBase::WiFiPAFMessageSend(WiFiPAFSession & TxInfo, PacketBufferHandle && msgBuf)
107105
{
108106
VerifyOrReturnError(mWiFiPAFLayer->GetWiFiPAFState() != State::kNotReady, CHIP_ERROR_INCORRECT_STATE);
109-
DeviceLayer::ConnectivityMgr().WiFiPAFSend(TxInfo, std::move(msgBuf));
110-
111-
return CHIP_NO_ERROR;
107+
return DeviceLayer::ConnectivityMgr().WiFiPAFSend(TxInfo, std::move(msgBuf));
112108
}
113109

114110
CHIP_ERROR WiFiPAFBase::WiFiPAFCloseSession(WiFiPAFSession & SessionInfo)
115111
{
116112
VerifyOrReturnError(mWiFiPAFLayer->GetWiFiPAFState() != State::kNotReady, CHIP_ERROR_INCORRECT_STATE);
117-
DeviceLayer::ConnectivityMgr().WiFiPAFShutdown(SessionInfo.id, SessionInfo.role);
113+
TEMPORARY_RETURN_IGNORED DeviceLayer::ConnectivityMgr().WiFiPAFShutdown(SessionInfo.id, SessionInfo.role);
118114
mWiFiPAFLayer->SetWiFiPAFState(State::kInitialized);
119115

120116
return CHIP_NO_ERROR;

src/wifipaf/WiFiPAFEndPoint.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ void WiFiPAFEndPoint::FinalizeClose(uint8_t oldState, uint8_t flags, CHIP_ERROR
228228
mSendQueue = nullptr;
229229
// Clear the session information
230230
ChipLogProgress(WiFiPAF, "Shutdown PAF session (%u, %u)", mSessionInfo.id, mSessionInfo.role);
231-
mWiFiPafLayer->mWiFiPAFTransport->WiFiPAFCloseSession(mSessionInfo);
231+
TEMPORARY_RETURN_IGNORED mWiFiPafLayer->mWiFiPAFTransport->WiFiPAFCloseSession(mSessionInfo);
232232
memset(&mSessionInfo, 0, sizeof(mSessionInfo));
233233
// Fire application's close callback if we haven't already, and it's not suppressed.
234234
if (oldState != kState_Closing && (flags & kWiFiPAFCloseFlag_SuppressCallback) == 0)
@@ -562,7 +562,7 @@ CHIP_ERROR WiFiPAFEndPoint::DoSendStandAloneAck()
562562
ChipLogDebugWiFiPAFEndPoint(WiFiPAF, "sending stand-alone ack");
563563

564564
// Encode and transmit stand-alone ack.
565-
mPafTP.EncodeStandAloneAck(mAckToSend);
565+
ReturnErrorOnFailure(mPafTP.EncodeStandAloneAck(mAckToSend));
566566
ReturnErrorOnFailure(SendCharacteristic(mAckToSend.Retain()));
567567

568568
// Reset local receive window counter.
@@ -605,8 +605,7 @@ CHIP_ERROR WiFiPAFEndPoint::DriveSending()
605605
if (!mWiFiPafLayer->mWiFiPAFTransport->WiFiPAFResourceAvailable() && (!mAckToSend.IsNull() || !mSendQueue.IsNull()))
606606
{
607607
// Resource is currently unavailable, send packets later
608-
StartWaitResourceTimer();
609-
return CHIP_NO_ERROR;
608+
return StartWaitResourceTimer();
610609
}
611610
mResourceWaitCount = 0;
612611

@@ -974,7 +973,7 @@ CHIP_ERROR WiFiPAFEndPoint::RxPacketProcess(PacketBufferHandle && data)
974973
bool didReceiveAck = false;
975974
BitFlags<WiFiPAFTP::HeaderFlags> rx_flags;
976975
Encoding::LittleEndian::Reader reader(data->Start(), data->DataLength());
977-
DebugPktAckSn(PktDirect_t::kRx, reader, data->Start());
976+
TEMPORARY_RETURN_IGNORED DebugPktAckSn(PktDirect_t::kRx, reader, data->Start());
978977

979978
{ // This is a special handling on the first CHIPoPAF data packet, the CapabilitiesRequest.
980979
// If we're receiving the first inbound packet of a PAF transport connection handshake...
@@ -1133,10 +1132,8 @@ CHIP_ERROR WiFiPAFEndPoint::SendWrite(PacketBufferHandle && buf)
11331132

11341133
ChipLogDebugBufferWiFiPAFEndPoint(WiFiPAF, buf);
11351134
Encoding::LittleEndian::Reader reader(buf->Start(), buf->DataLength());
1136-
DebugPktAckSn(PktDirect_t::kTx, reader, buf->Start());
1137-
mWiFiPafLayer->mWiFiPAFTransport->WiFiPAFMessageSend(mSessionInfo, std::move(buf));
1138-
1139-
return CHIP_NO_ERROR;
1135+
TEMPORARY_RETURN_IGNORED DebugPktAckSn(PktDirect_t::kTx, reader, buf->Start());
1136+
return mWiFiPafLayer->mWiFiPAFTransport->WiFiPAFMessageSend(mSessionInfo, std::move(buf));
11401137
}
11411138

11421139
CHIP_ERROR WiFiPAFEndPoint::StartConnectTimer()

src/wifipaf/WiFiPAFLayer.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,7 @@ CHIP_ERROR WiFiPAFLayer::NewEndPoint(WiFiPAFEndPoint ** retEndPoint, WiFiPAFSess
328328
ChipLogError(WiFiPAF, "endpoint pool FULL");
329329
return CHIP_ERROR_ENDPOINT_POOL_FULL;
330330
}
331-
(*retEndPoint)->Init(this, SessionInfo);
332-
333-
return CHIP_NO_ERROR;
331+
return (*retEndPoint)->Init(this, SessionInfo);
334332
}
335333

336334
CHIP_ERROR WiFiPAFLayer::HandleTransportConnectionInitiated(WiFiPAF::WiFiPAFSession & SessionInfo,

0 commit comments

Comments
 (0)