Skip to content

Commit

Permalink
fix: cast int operands to size_t in bio buffer size calc to prevent l…
Browse files Browse the repository at this point in the history
…oss of precision
  • Loading branch information
gasbytes committed Dec 21, 2024
1 parent 4c58ece commit a1d77da
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,8 @@ static int wolfSSL_BIO_MEMORY_write(WOLFSSL_BIO* bio, const void* data,
if (len == 0)
return WOLFSSL_SUCCESS; /* Return early to make logic simpler */

if (wolfSSL_BUF_MEM_grow_ex(bio->mem_buf, (size_t)(bio->wrSz + len), 0)
== 0) {
if (wolfSSL_BUF_MEM_grow_ex(bio->mem_buf, ((size_t)bio->wrSz) +
((size_t)len), 0) == 0) {
WOLFSSL_MSG("Error growing memory area");
return WOLFSSL_FAILURE;
}
Expand Down Expand Up @@ -1322,7 +1322,8 @@ size_t wolfSSL_BIO_ctrl_pending(WOLFSSL_BIO *bio)
if (pair->wrIdx > 0 && pair->wrIdx <= pair->rdIdx) {
/* in wrap around state where beginning of buffer is being
* overwritten */
return (size_t)(pair->wrSz - pair->rdIdx + pair->wrIdx);
return ((size_t)pair->wrSz) - ((size_t)pair->rdIdx) +
((size_t)pair->wrIdx);
}
else {
/* simple case where has not wrapped around */
Expand Down

0 comments on commit a1d77da

Please sign in to comment.