Improvements to error handling for AddSessionToClientCache.

This commit is contained in:
David Garske
2022-07-08 09:06:51 -07:00
parent 03a32250da
commit 720030b5a9

View File

@@ -13548,32 +13548,43 @@ ClientSession* AddSessionToClientCache(int side, int row, int idx, byte* serverI
clientRow = HashSession(sessionID, clientRow = HashSession(sessionID,
ID_LEN, &error) % CLIENT_SESSION_ROWS; ID_LEN, &error) % CLIENT_SESSION_ROWS;
} }
else else {
error = -1; error = -1;
}
if (error == 0 && wc_LockMutex(&clisession_mutex) == 0) { if (error == 0 && wc_LockMutex(&clisession_mutex) == 0) {
clientIdx = ClientCache[clientRow].nextIdx++; clientIdx = ClientCache[clientRow].nextIdx;
ClientCache[clientRow].Clients[clientIdx].serverRow = if (clientIdx < CLIENT_SESSIONS_PER_ROW) {
(word16)row; ClientCache[clientRow].Clients[clientIdx].serverRow =
ClientCache[clientRow].Clients[clientIdx].serverIdx = (word16)row;
(word16)idx; ClientCache[clientRow].Clients[clientIdx].serverIdx =
if (sessionID != NULL) { (word16)idx;
sessionIDHash = HashSession(sessionID, ID_LEN, &error); if (sessionID != NULL) {
if (error == 0) { sessionIDHash = HashSession(sessionID, ID_LEN, &error);
ClientCache[clientRow].Clients[clientIdx].sessionIDHash if (error == 0) {
= sessionIDHash; ClientCache[clientRow].Clients[clientIdx].sessionIDHash
= sessionIDHash;
}
} }
} }
else {
error = -1;
ClientCache[clientRow].nextIdx = 0; /* reset index as saftey */
WOLFSSL_MSG("Invalid client cache index! "
"Possible corrupted memory");
}
if (error == 0) { if (error == 0) {
WOLFSSL_MSG("Adding client cache entry"); WOLFSSL_MSG("Adding client cache entry");
if (ClientCache[clientRow].totalCount < CLIENT_SESSIONS_PER_ROW) if (ClientCache[clientRow].totalCount < CLIENT_SESSIONS_PER_ROW)
ClientCache[clientRow].totalCount++; ClientCache[clientRow].totalCount++;
ClientCache[clientRow].nextIdx++;
ClientCache[clientRow].nextIdx %= CLIENT_SESSIONS_PER_ROW; ClientCache[clientRow].nextIdx %= CLIENT_SESSIONS_PER_ROW;
} }
wc_UnLockMutex(&clisession_mutex); wc_UnLockMutex(&clisession_mutex);
} }
else { else {
WOLFSSL_MSG("Hash session failed"); WOLFSSL_MSG("Hash session or lock failed");
error = -1;
} }
} }
else { else {