Skip to content

Commit c892bf8

Browse files
committed
Consistently fail on mutex error
1 parent 24aa260 commit c892bf8

2 files changed

Lines changed: 29 additions & 29 deletions

File tree

src/dtls13.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,13 +2039,13 @@ int Dtls13HandshakeSend(WOLFSSL* ssl, byte* message, word16 outputSize,
20392039
#ifdef HAVE_WRITE_DUP
20402040
/* Notify the read side so it can watch for the ACK on our behalf. */
20412041
if (ssl->dupWrite != NULL && ssl->dupSide == WRITE_DUP_SIDE) {
2042-
if (wc_LockMutex(&ssl->dupWrite->dupMutex) == 0) {
2043-
ssl->dupWrite->keyUpdateEpoch = ssl->dtls13Epoch;
2044-
ssl->dupWrite->keyUpdateSeq =
2045-
ssl->dtls13EncryptEpoch->nextSeqNumber;
2046-
ssl->dupWrite->keyUpdateWaiting = 1;
2047-
wc_UnLockMutex(&ssl->dupWrite->dupMutex);
2048-
}
2042+
if (wc_LockMutex(&ssl->dupWrite->dupMutex) != 0)
2043+
return BAD_MUTEX_E;
2044+
ssl->dupWrite->keyUpdateEpoch = ssl->dtls13Epoch;
2045+
ssl->dupWrite->keyUpdateSeq =
2046+
ssl->dtls13EncryptEpoch->nextSeqNumber;
2047+
ssl->dupWrite->keyUpdateWaiting = 1;
2048+
wc_UnLockMutex(&ssl->dupWrite->dupMutex);
20492049
}
20502050
#endif /* HAVE_WRITE_DUP */
20512051
}
@@ -2723,16 +2723,16 @@ int Dtls13DoScheduledWork(WOLFSSL* ssl)
27232723
/* The read side cannot encrypt. Transfer the seenRecords list to the
27242724
* shared WriteDup struct so the write side sends the ACK instead. */
27252725
if (ssl->dupWrite != NULL && ssl->dupSide == READ_DUP_SIDE) {
2726-
if (wc_LockMutex(&ssl->dupWrite->dupMutex) == 0) {
2727-
struct Dtls13RecordNumber** tail =
2728-
(struct Dtls13RecordNumber**)&ssl->dupWrite->sendAckList;
2729-
while (*tail != NULL)
2730-
tail = &(*tail)->next;
2731-
*tail = ssl->dtls13Rtx.seenRecords;
2732-
ssl->dtls13Rtx.seenRecords = NULL;
2733-
ssl->dupWrite->sendAcks = 1;
2734-
wc_UnLockMutex(&ssl->dupWrite->dupMutex);
2735-
}
2726+
struct Dtls13RecordNumber** tail = NULL;
2727+
if (wc_LockMutex(&ssl->dupWrite->dupMutex) != 0)
2728+
return BAD_MUTEX_E;
2729+
tail = (struct Dtls13RecordNumber**)&ssl->dupWrite->sendAckList;
2730+
while (*tail != NULL)
2731+
tail = &(*tail)->next;
2732+
*tail = ssl->dtls13Rtx.seenRecords;
2733+
ssl->dtls13Rtx.seenRecords = NULL;
2734+
ssl->dupWrite->sendAcks = 1;
2735+
wc_UnLockMutex(&ssl->dupWrite->dupMutex);
27362736
}
27372737
else
27382738
#endif /* HAVE_WRITE_DUP */
@@ -2861,15 +2861,15 @@ int DoDtls13Ack(WOLFSSL* ssl, const byte* input, word32 inputSize,
28612861
* Match on both epoch AND seq to avoid false positives from data records
28622862
* in the same epoch (sent while dtls13WaitKeyUpdateAck == 1). */
28632863
if (ssl->dupWrite != NULL && ssl->dupSide == READ_DUP_SIDE) {
2864-
if (wc_LockMutex(&ssl->dupWrite->dupMutex) == 0) {
2865-
if (ssl->dupWrite->keyUpdateWaiting &&
2866-
w64Equal(epoch, ssl->dupWrite->keyUpdateEpoch) &&
2867-
w64Equal(seq, ssl->dupWrite->keyUpdateSeq)) {
2868-
ssl->dupWrite->keyUpdateAcked = 1;
2869-
ssl->dupWrite->keyUpdateWaiting = 0;
2870-
}
2871-
wc_UnLockMutex(&ssl->dupWrite->dupMutex);
2864+
if (wc_LockMutex(&ssl->dupWrite->dupMutex) != 0)
2865+
return BAD_MUTEX_E;
2866+
if (ssl->dupWrite->keyUpdateWaiting &&
2867+
w64Equal(epoch, ssl->dupWrite->keyUpdateEpoch) &&
2868+
w64Equal(seq, ssl->dupWrite->keyUpdateSeq)) {
2869+
ssl->dupWrite->keyUpdateAcked = 1;
2870+
ssl->dupWrite->keyUpdateWaiting = 0;
28722871
}
2872+
wc_UnLockMutex(&ssl->dupWrite->dupMutex);
28732873
}
28742874
#endif /* HAVE_WRITE_DUP */
28752875
}

src/tls13.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11822,10 +11822,10 @@ static int DoTls13KeyUpdate(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
1182211822
#if defined(HAVE_WRITE_DUP) && defined(WOLFSSL_TLS13)
1182311823
/* Read side cannot write; delegate the response to the write side. */
1182411824
if (ssl->dupWrite != NULL && ssl->dupSide == READ_DUP_SIDE) {
11825-
if (wc_LockMutex(&ssl->dupWrite->dupMutex) == 0) {
11826-
ssl->dupWrite->keyUpdateRespond = 1;
11827-
wc_UnLockMutex(&ssl->dupWrite->dupMutex);
11828-
}
11825+
if (wc_LockMutex(&ssl->dupWrite->dupMutex) != 0)
11826+
return BAD_MUTEX_E;
11827+
ssl->dupWrite->keyUpdateRespond = 1;
11828+
wc_UnLockMutex(&ssl->dupWrite->dupMutex);
1182911829
ssl->keys.keyUpdateRespond = 0;
1183011830
return 0;
1183111831
}

0 commit comments

Comments
 (0)