Skip to content

Commit fdab1ae

Browse files
committed
Fix from review
1 parent 2abd10e commit fdab1ae

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

src/mqtt_broker.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@
135135
* Iterates exactly cmp_len times so loop duration is independent of
136136
* either input's length; cmp_len is a caller-supplied fixed bound
137137
* (the credential buffer size). Length mismatch is folded in via the
138-
* final XOR. Returns 0 if equal, non-zero if different. */
138+
* final XOR. Inputs with length >= cmp_len force a mismatch to prevent
139+
* bypass when both strings match in the first cmp_len bytes but differ
140+
* beyond. Returns 0 if equal, non-zero if different. */
139141
static int BrokerStrCompare(const char* a, const char* b, int cmp_len)
140142
{
141143
int result = 0;
@@ -152,6 +154,10 @@ static int BrokerStrCompare(const char* a, const char* b, int cmp_len)
152154
result |= (a[ia] ^ b[ib]);
153155
}
154156
result |= (len_a ^ len_b);
157+
/* Force mismatch if either input meets or exceeds cmp_len, since the
158+
* loop cannot observe bytes beyond that bound. */
159+
result |= (len_a >= cmp_len);
160+
result |= (len_b >= cmp_len);
155161
return result;
156162
}
157163
#endif /* WOLFMQTT_BROKER_AUTH */

src/mqtt_client.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1739,9 +1739,11 @@ int MqttClient_Connect(MqttClient *client, MqttConnect *mc_connect)
17391739
wm_SemUnlock(&client->lockClient);
17401740
}
17411741
if (rc != 0) {
1742+
/* Save write.len before MqttWriteStop zeroes client->write */
1743+
int xfer = client->write.len;
17421744
MqttWriteStop(client, &mc_connect->stat);
17431745
/* Clear tx_buf to remove plaintext credentials before returning */
1744-
CLIENT_FORCE_ZERO(client->tx_buf, client->write.len);
1746+
CLIENT_FORCE_ZERO(client->tx_buf, xfer);
17451747
return rc; /* Error locking client */
17461748
}
17471749
#endif

0 commit comments

Comments
 (0)