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,10 +13548,12 @@ 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;
if (clientIdx < CLIENT_SESSIONS_PER_ROW) {
ClientCache[clientRow].Clients[clientIdx].serverRow = ClientCache[clientRow].Clients[clientIdx].serverRow =
(word16)row; (word16)row;
ClientCache[clientRow].Clients[clientIdx].serverIdx = ClientCache[clientRow].Clients[clientIdx].serverIdx =
@@ -13563,17 +13565,26 @@ ClientSession* AddSessionToClientCache(int side, int row, int idx, byte* serverI
= 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 {