Skip to content

Commit

Permalink
Fix conversion on various files. Work from Reda.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgarske committed Nov 27, 2024
1 parent e9a4f7d commit 81ae002
Show file tree
Hide file tree
Showing 22 changed files with 256 additions and 228 deletions.
57 changes: 30 additions & 27 deletions src/bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ static int wolfSSL_BIO_BIO_read(WOLFSSL_BIO* bio, void* buf, int len)
bio->flags &= ~(WOLFSSL_BIO_FLAG_READ|WOLFSSL_BIO_FLAG_RETRY);
sz1 = wolfSSL_BIO_nread(bio, &pt, len);
if (sz1 > 0) {
XMEMCPY(buf, pt, sz1);
XMEMCPY(buf, pt, (size_t)sz1);
buf = (char*)buf + sz1;
len -= sz1;
if (len > 0) {
/* try again to see if maybe we wrapped around the ring buffer */
sz2 = wolfSSL_BIO_nread(bio, &pt, len);
if (sz2 > 0) {
XMEMCPY(buf, pt, sz2);
XMEMCPY(buf, pt, (size_t)sz2);
sz1 += sz2;
}
}
Expand Down Expand Up @@ -142,7 +142,7 @@ static int wolfSSL_BIO_MEMORY_read(WOLFSSL_BIO* bio, void* buf, int len)
return WOLFSSL_BIO_ERROR;
}

XMEMCPY(buf, bio->mem_buf->data + bio->rdIdx, sz);
XMEMCPY(buf, bio->mem_buf->data + bio->rdIdx, (size_t)sz);
bio->rdIdx += sz;

if (bio->rdIdx >= bio->wrSz) {
Expand All @@ -167,14 +167,14 @@ static int wolfSSL_BIO_MEMORY_read(WOLFSSL_BIO* bio, void* buf, int len)
/* Resize the memory so we are not taking up more than necessary.
* memmove reverts internally to memcpy if areas don't overlap */
XMEMMOVE(bio->mem_buf->data, bio->mem_buf->data + bio->rdIdx,
bio->wrSz - bio->rdIdx);
(long unsigned int)bio->wrSz - (size_t)bio->rdIdx);
bio->wrSz -= bio->rdIdx;
bio->rdIdx = 0;
/* Resize down to WOLFSSL_BIO_RESIZE_THRESHOLD for fewer
* allocations. */
if (wolfSSL_BUF_MEM_resize(bio->mem_buf,
bio->wrSz > WOLFSSL_BIO_RESIZE_THRESHOLD ? bio->wrSz :
WOLFSSL_BIO_RESIZE_THRESHOLD) == 0) {
bio->wrSz > WOLFSSL_BIO_RESIZE_THRESHOLD ?
(size_t)bio->wrSz : WOLFSSL_BIO_RESIZE_THRESHOLD) == 0) {
WOLFSSL_MSG("wolfSSL_BUF_MEM_resize error");
return WOLFSSL_BIO_ERROR;
}
Expand Down Expand Up @@ -562,15 +562,15 @@ static int wolfSSL_BIO_BIO_write(WOLFSSL_BIO* bio, const void* data,
WOLFSSL_MSG("Error in wolfSSL_BIO_nwrite");
return sz1;
}
XMEMCPY(buf, data, sz1);
XMEMCPY(buf, data, (size_t)sz1);
data = (char*)data + sz1;
len -= sz1;

if (len > 0) {
/* try again to see if maybe we wrapped around the ring buffer */
sz2 = wolfSSL_BIO_nwrite(bio, &buf, len);
if (sz2 > 0) {
XMEMCPY(buf, data, sz2);
XMEMCPY(buf, data, (size_t)sz2);
sz1 += sz2;
if (len > sz2)
bio->flags |= WOLFSSL_BIO_FLAG_WRITE|WOLFSSL_BIO_FLAG_RETRY;
Expand Down Expand Up @@ -619,7 +619,7 @@ static int wolfSSL_BIO_MEMORY_write(WOLFSSL_BIO* bio, const void* data,
return WOLFSSL_FAILURE;
}

XMEMCPY(bio->mem_buf->data + bio->wrSz, data, len);
XMEMCPY(bio->mem_buf->data + bio->wrSz, data, (size_t)len);
bio->ptr.mem_buf_data = (byte *)bio->mem_buf->data;
bio->num.length = bio->mem_buf->max;
bio->wrSz += len;
Expand Down Expand Up @@ -1136,7 +1136,7 @@ int wolfSSL_BIO_gets(WOLFSSL_BIO* bio, char* buf, int sz)

ret = wolfSSL_BIO_nread(bio, &c, cSz);
if (ret > 0 && ret < sz) {
XMEMCPY(buf, c, ret);
XMEMCPY(buf, c, (size_t)ret);
}
break;
}
Expand Down Expand Up @@ -1254,13 +1254,13 @@ size_t wolfSSL_BIO_wpending(const WOLFSSL_BIO *bio)
return 0;

if (bio->type == WOLFSSL_BIO_MEMORY) {
return bio->wrSz;
return (size_t)bio->wrSz;
}

/* type BIO_BIO then check paired buffer */
if (bio->type == WOLFSSL_BIO_BIO && bio->pair != NULL) {
WOLFSSL_BIO* pair = bio->pair;
return pair->wrIdx;
return (size_t)pair->wrIdx;
}

return 0;
Expand Down Expand Up @@ -1306,12 +1306,12 @@ size_t wolfSSL_BIO_ctrl_pending(WOLFSSL_BIO *bio)

#ifndef WOLFCRYPT_ONLY
if (bio->type == WOLFSSL_BIO_SSL && bio->ptr.ssl != NULL) {
return (long)wolfSSL_pending(bio->ptr.ssl);
return (size_t)wolfSSL_pending(bio->ptr.ssl);
}
#endif

if (bio->type == WOLFSSL_BIO_MEMORY) {
return bio->wrSz - bio->rdIdx;
return (size_t)(bio->wrSz - bio->rdIdx);
}

/* type BIO_BIO then check paired buffer */
Expand All @@ -1324,7 +1324,7 @@ size_t wolfSSL_BIO_ctrl_pending(WOLFSSL_BIO *bio)
}
else {
/* simple case where has not wrapped around */
return pair->wrIdx - pair->rdIdx;
return (size_t)(pair->wrIdx - pair->rdIdx);
}
}
return 0;
Expand Down Expand Up @@ -1421,7 +1421,7 @@ int wolfSSL_BIO_set_write_buf_size(WOLFSSL_BIO *bio, long size)
XFREE(bio->ptr.mem_buf_data, bio->heap, DYNAMIC_TYPE_OPENSSL);
}

bio->ptr.mem_buf_data = (byte*)XMALLOC(size, bio->heap,
bio->ptr.mem_buf_data = (byte*)XMALLOC((size_t)size, bio->heap,
DYNAMIC_TYPE_OPENSSL);
if (bio->ptr.mem_buf_data == NULL) {
WOLFSSL_MSG("Memory allocation error");
Expand All @@ -1437,7 +1437,7 @@ int wolfSSL_BIO_set_write_buf_size(WOLFSSL_BIO *bio, long size)
return WOLFSSL_FAILURE;
}
bio->wrSz = (int)size;
bio->num.length = size;
bio->num.length = (size_t)size;
bio->wrIdx = 0;
bio->rdIdx = 0;
if (bio->mem_buf != NULL) {
Expand Down Expand Up @@ -2379,10 +2379,11 @@ int wolfSSL_BIO_flush(WOLFSSL_BIO* bio)
else
port = str + XSTRLEN(str); /* point to null terminator */

bio->ip = (char*)XMALLOC((port - str) + 1, /* +1 for null char */
bio->ip = (char*)XMALLOC(
(size_t)(port - str) + 1, /* +1 for null char */
bio->heap, DYNAMIC_TYPE_OPENSSL);
if (bio->ip != NULL) {
XMEMCPY(bio->ip, str, port - str);
XMEMCPY(bio->ip, str, (size_t)(port - str));
bio->ip[port - str] = '\0';
bio->type = WOLFSSL_BIO_SOCKET;
}
Expand Down Expand Up @@ -2922,7 +2923,7 @@ int wolfSSL_BIO_flush(WOLFSSL_BIO* bio)
bio->wrSz = len;
bio->ptr.mem_buf_data = (byte *)bio->mem_buf->data;
if (len > 0 && bio->ptr.mem_buf_data != NULL) {
XMEMCPY(bio->ptr.mem_buf_data, buf, len);
XMEMCPY(bio->ptr.mem_buf_data, buf, (size_t)len);
bio->flags |= WOLFSSL_BIO_FLAG_MEM_RDONLY;
bio->wrSzReset = bio->wrSz;
}
Expand Down Expand Up @@ -3291,11 +3292,11 @@ int wolfSSL_BIO_vprintf(WOLFSSL_BIO* bio, const char* format, va_list args)
count = XVSNPRINTF(NULL, 0, format, args);
if (count >= 0)
{
pt = (char*)XMALLOC(count + 1, bio->heap,
pt = (char*)XMALLOC((size_t)count + 1, bio->heap,
DYNAMIC_TYPE_TMP_BUFFER);
if (pt != NULL)
{
count = XVSNPRINTF(pt, count + 1, format, copy);
count = XVSNPRINTF(pt, (size_t)count + 1, format, copy);
if (count >= 0)
{
ret = wolfSSL_BIO_write(bio, pt, count);
Expand Down Expand Up @@ -3365,18 +3366,20 @@ int wolfSSL_BIO_dump(WOLFSSL_BIO *bio, const char *buf, int length)
o = 7;
for (i = 0; i < BIO_DUMP_LINE_LEN; i++) {
if (i < length)
(void)XSNPRINTF(line + o, (int)sizeof(line) - o,
(void)XSNPRINTF(line + o, (size_t)((int)sizeof(line) - o),
"%02x ", (unsigned char)buf[i]);
else
(void)XSNPRINTF(line + o, (int)sizeof(line) - o, " ");
(void)XSNPRINTF(line + o, (size_t)((int)sizeof(line) - o),
" ");
if (i == 7)
(void)XSNPRINTF(line + o + 2, (int)sizeof(line) - (o + 2), "-");
(void)XSNPRINTF(line + o + 2, (size_t)((int)sizeof(line) -
(o + 2)), "-");
o += 3;
}
(void)XSNPRINTF(line + o, (int)sizeof(line) - o, " ");
(void)XSNPRINTF(line + o, (size_t)((int)sizeof(line) - o), " ");
o += 2;
for (i = 0; (i < BIO_DUMP_LINE_LEN) && (i < length); i++) {
(void)XSNPRINTF(line + o, (int)sizeof(line) - o, "%c",
(void)XSNPRINTF(line + o, (size_t)((int)sizeof(line) - o), "%c",
((31 < buf[i]) && (buf[i] < 127)) ? buf[i] : '.');
o++;
}
Expand Down
11 changes: 6 additions & 5 deletions src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -7037,7 +7037,7 @@ void FreeHandshakeHashes(WOLFSSL* ssl)
(defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3))) && \
!defined(WOLFSSL_NO_CLIENT_AUTH)
if (ssl->hsHashes->messages != NULL) {
ForceZero(ssl->hsHashes->messages, ssl->hsHashes->length);
ForceZero(ssl->hsHashes->messages, (word32)ssl->hsHashes->length);
XFREE(ssl->hsHashes->messages, ssl->heap, DYNAMIC_TYPE_HASHES);
ssl->hsHashes->messages = NULL;
}
Expand Down Expand Up @@ -7105,8 +7105,9 @@ int InitHandshakeHashesAndCopy(WOLFSSL* ssl, HS_Hashes* source,
(defined(WOLFSSL_SM2) && defined(WOLFSSL_SM3))) && \
!defined(WOLFSSL_NO_CLIENT_AUTH)
if (ret == 0 && source->messages != NULL) {
(*destination)->messages = (byte*)XMALLOC(source->length, ssl->heap,
DYNAMIC_TYPE_HASHES);
(*destination)->messages = (byte*)XMALLOC((size_t)source->length,
ssl->heap,
(int)DYNAMIC_TYPE_HASHES);
(*destination)->length = source->length;
(*destination)->prevLen = source->prevLen;

Expand All @@ -7115,7 +7116,7 @@ int InitHandshakeHashesAndCopy(WOLFSSL* ssl, HS_Hashes* source,
}
else {
XMEMCPY((*destination)->messages, source->messages,
source->length);
(size_t)source->length);
}
}
#endif
Expand Down Expand Up @@ -9598,7 +9599,7 @@ int DtlsMsgPoolSend(WOLFSSL* ssl, int sendOnlyFirstPacket)

WriteSEQ(ssl, epochOrder, dtls->sequence_number);
DtlsSEQIncrement(ssl, epochOrder);
if ((ret = CheckAvailableSize(ssl, pool->sz)) != 0) {
if ((ret = CheckAvailableSize(ssl, (int)pool->sz)) != 0) {
WOLFSSL_ERROR(ret);
return ret;
}
Expand Down
12 changes: 7 additions & 5 deletions src/keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -3908,7 +3908,8 @@ int DeriveKeys(WOLFSSL* ssl)
XMEMCPY(shaInput + idx, ssl->arrays->clientRandom, RAN_LEN);
if (ret == 0) {
ret = wc_ShaUpdate(sha, shaInput,
(KEY_PREFIX + SECRET_LEN + 2 * RAN_LEN) - KEY_PREFIX + j);
(KEY_PREFIX + SECRET_LEN + 2 * RAN_LEN) - KEY_PREFIX +
(word32)(j));
}
if (ret == 0) {
ret = wc_ShaFinal(sha, shaOutput);
Expand Down Expand Up @@ -3942,12 +3943,13 @@ int DeriveKeys(WOLFSSL* ssl)

static int CleanPreMaster(WOLFSSL* ssl)
{
int i, ret, sz = ssl->arrays->preMasterSz;
int i, ret, sz = (int)(ssl->arrays->preMasterSz);

for (i = 0; i < sz; i++)
ssl->arrays->preMasterSecret[i] = 0;

ret = wc_RNG_GenerateBlock(ssl->rng, ssl->arrays->preMasterSecret, sz);
ret = wc_RNG_GenerateBlock(ssl->rng, ssl->arrays->preMasterSecret,
(word32)(sz));
if (ret != 0)
return ret;

Expand Down Expand Up @@ -4035,8 +4037,8 @@ static int MakeSslMasterSecret(WOLFSSL* ssl)
}

idx = 0;
XMEMCPY(shaInput, prefix, i + 1);
idx += i + 1;
XMEMCPY(shaInput, prefix, (size_t)(i + 1));
idx += (word32)(i + 1);

XMEMCPY(shaInput + idx, ssl->arrays->preMasterSecret, pmsSz);
idx += pmsSz;
Expand Down
Loading

0 comments on commit 81ae002

Please sign in to comment.