Fix conversion error in wolfio.c

This commit is contained in:
Andras Fekete
2024-05-08 15:41:24 -04:00
parent affd0a318e
commit 692a7d55ff

View File

@ -558,7 +558,7 @@ int EmbedReceiveFrom(WOLFSSL *ssl, char *buf, int sz, void *ctx)
start = LowResTimer(); start = LowResTimer();
} }
else { else {
dtls_timeout -= LowResTimer() - start; dtls_timeout -= (int) (LowResTimer() - start);
start = LowResTimer(); start = LowResTimer();
if (dtls_timeout < 0 || dtls_timeout > DTLS_TIMEOUT_MAX) if (dtls_timeout < 0 || dtls_timeout > DTLS_TIMEOUT_MAX)
return WOLFSSL_CBIO_ERR_TIMEOUT; return WOLFSSL_CBIO_ERR_TIMEOUT;
@ -608,7 +608,7 @@ int EmbedReceiveFrom(WOLFSSL *ssl, char *buf, int sz, void *ctx)
} }
#endif /* !NO_ASN_TIME */ #endif /* !NO_ASN_TIME */
recvd = (int)DTLS_RECVFROM_FUNCTION(sd, buf, sz, ssl->rflags, recvd = (int)DTLS_RECVFROM_FUNCTION(sd, buf, (size_t)sz, ssl->rflags,
(SOCKADDR*)peer, peer != NULL ? &peerSz : NULL); (SOCKADDR*)peer, peer != NULL ? &peerSz : NULL);
/* From the RECV(2) man page /* From the RECV(2) man page
@ -716,7 +716,7 @@ int EmbedSendTo(WOLFSSL* ssl, char *buf, int sz, void *ctx)
#endif #endif
} }
sent = (int)DTLS_SENDTO_FUNCTION(sd, buf, sz, ssl->wflags, sent = (int)DTLS_SENDTO_FUNCTION(sd, buf, (size_t)sz, ssl->wflags,
(const SOCKADDR*)peer, peerSz); (const SOCKADDR*)peer, peerSz);
sent = TranslateReturnCode(sent, sd); sent = TranslateReturnCode(sent, sd);
@ -743,7 +743,7 @@ int EmbedReceiveFromMcast(WOLFSSL *ssl, char *buf, int sz, void *ctx)
WOLFSSL_ENTER("EmbedReceiveFromMcast"); WOLFSSL_ENTER("EmbedReceiveFromMcast");
recvd = (int)DTLS_RECVFROM_FUNCTION(sd, buf, sz, ssl->rflags, NULL, NULL); recvd = (int)DTLS_RECVFROM_FUNCTION(sd, buf, (size_t)sz, ssl->rflags, NULL, NULL);
recvd = TranslateReturnCode(recvd, sd); recvd = TranslateReturnCode(recvd, sd);
@ -787,7 +787,7 @@ int EmbedGenerateCookie(WOLFSSL* ssl, byte *buf, int sz, void *ctx)
if (sz > WC_SHA256_DIGEST_SIZE) if (sz > WC_SHA256_DIGEST_SIZE)
sz = WC_SHA256_DIGEST_SIZE; sz = WC_SHA256_DIGEST_SIZE;
XMEMCPY(buf, digest, sz); XMEMCPY(buf, digest, (size_t)sz);
return sz; return sz;
} }
@ -981,7 +981,7 @@ int wolfIO_Recv(SOCKET_T sd, char *buf, int sz, int rdFlags)
{ {
int recvd; int recvd;
recvd = (int)RECV_FUNCTION(sd, buf, sz, rdFlags); recvd = (int)RECV_FUNCTION(sd, buf, (size_t)sz, rdFlags);
recvd = TranslateReturnCode(recvd, (int)sd); recvd = TranslateReturnCode(recvd, (int)sd);
return recvd; return recvd;
@ -991,7 +991,7 @@ int wolfIO_Send(SOCKET_T sd, char *buf, int sz, int wrFlags)
{ {
int sent; int sent;
sent = (int)SEND_FUNCTION(sd, buf, sz, wrFlags); sent = (int)SEND_FUNCTION(sd, buf, (size_t)sz, wrFlags);
sent = TranslateReturnCode(sent, (int)sd); sent = TranslateReturnCode(sent, (int)sd);
return sent; return sent;
@ -1083,9 +1083,9 @@ int wolfIO_Send(SOCKET_T sd, char *buf, int sz, int wrFlags)
} }
#endif /* HAVE_IO_TIMEOUT */ #endif /* HAVE_IO_TIMEOUT */
static int wolfIO_Word16ToString(char* d, word16 number) static word32 wolfIO_Word16ToString(char* d, word16 number)
{ {
int i = 0; word32 i = 0;
word16 order = 10000; word16 order = 10000;
word16 digit; word16 digit;
@ -1100,7 +1100,7 @@ static int wolfIO_Word16ToString(char* d, word16 number)
if (i > 0 || digit != 0) if (i > 0 || digit != 0)
d[i++] = (char)digit + '0'; d[i++] = (char)digit + '0';
if (digit != 0) if (digit != 0)
number %= digit * order; number = (word16) (number % (digit * order));
order = (order > 1) ? order / 10 : 0; order = (order > 1) ? order / 10 : 0;
} }
@ -1115,7 +1115,7 @@ int wolfIO_TcpConnect(SOCKET_T* sockfd, const char* ip, word16 port, int to_sec)
#ifdef HAVE_SOCKADDR #ifdef HAVE_SOCKADDR
int ret = 0; int ret = 0;
SOCKADDR_S addr; SOCKADDR_S addr;
int sockaddr_len; socklen_t sockaddr_len;
#if defined(HAVE_GETADDRINFO) #if defined(HAVE_GETADDRINFO)
/* use getaddrinfo */ /* use getaddrinfo */
ADDRINFO hints; ADDRINFO hints;
@ -1179,7 +1179,7 @@ int wolfIO_TcpConnect(SOCKET_T* sockfd, const char* ip, word16 port, int to_sec)
} }
sockaddr_len = answer->ai_addrlen; sockaddr_len = answer->ai_addrlen;
XMEMCPY(&addr, answer->ai_addr, sockaddr_len); XMEMCPY(&addr, answer->ai_addr, (size_t)sockaddr_len);
freeaddrinfo(answer); freeaddrinfo(answer);
#elif defined(WOLFSSL_USE_POPEN_HOST) && !defined(WOLFSSL_IPV6) #elif defined(WOLFSSL_USE_POPEN_HOST) && !defined(WOLFSSL_IPV6)
{ {
@ -1342,7 +1342,7 @@ int wolfIO_TcpBind(SOCKET_T* sockfd, word16 port)
#ifdef HAVE_SOCKADDR #ifdef HAVE_SOCKADDR
int ret = 0; int ret = 0;
SOCKADDR_S addr; SOCKADDR_S addr;
int sockaddr_len = sizeof(SOCKADDR_IN); socklen_t sockaddr_len = sizeof(SOCKADDR_IN);
SOCKADDR_IN *sin = (SOCKADDR_IN *)&addr; SOCKADDR_IN *sin = (SOCKADDR_IN *)&addr;
if (sockfd == NULL || port < 1) { if (sockfd == NULL || port < 1) {
@ -1473,7 +1473,7 @@ int wolfIO_DecodeUrl(const char* url, int urlSz, char* outName, char* outPath,
for (j = 0; j < i; j++) { for (j = 0; j < i; j++) {
if (port[j] < '0' || port[j] > '9') return -1; if (port[j] < '0' || port[j] > '9') return -1;
bigPort = (bigPort * 10) + (port[j] - '0'); bigPort = (bigPort * 10) + (word32)(port[j] - '0');
} }
if (outPort) if (outPort)
*outPort = (word16)bigPort; *outPort = (word16)bigPort;
@ -1528,7 +1528,7 @@ static int wolfIO_HttpProcessResponseBuf(int sfd, byte **recvBuf,
return MEMORY_E; return MEMORY_E;
} }
newRecvBuf = (byte*)XMALLOC(newRecvSz, heap, dynType); newRecvBuf = (byte*)XMALLOC((size_t)newRecvSz, heap, dynType);
if (newRecvBuf == NULL) { if (newRecvBuf == NULL) {
WOLFSSL_MSG("wolfIO_HttpProcessResponseBuf malloc failed"); WOLFSSL_MSG("wolfIO_HttpProcessResponseBuf malloc failed");
return MEMORY_E; return MEMORY_E;
@ -1536,7 +1536,7 @@ static int wolfIO_HttpProcessResponseBuf(int sfd, byte **recvBuf,
/* if buffer already exists, then we are growing it */ /* if buffer already exists, then we are growing it */
if (*recvBuf) { if (*recvBuf) {
XMEMCPY(&newRecvBuf[pos], *recvBuf, *recvBufSz); XMEMCPY(&newRecvBuf[pos], *recvBuf, (size_t) *recvBufSz);
XFREE(*recvBuf, heap, dynType); XFREE(*recvBuf, heap, dynType);
pos += *recvBufSz; pos += *recvBufSz;
*recvBuf = NULL; *recvBuf = NULL;
@ -1545,7 +1545,7 @@ static int wolfIO_HttpProcessResponseBuf(int sfd, byte **recvBuf,
/* copy the remainder of the httpBuf into the respBuf */ /* copy the remainder of the httpBuf into the respBuf */
if (len != 0) { if (len != 0) {
if (pos + len <= newRecvSz) { if (pos + len <= newRecvSz) {
XMEMCPY(&newRecvBuf[pos], start, len); XMEMCPY(&newRecvBuf[pos], start, (size_t)len);
pos += len; pos += len;
} }
else { else {
@ -1629,7 +1629,7 @@ int wolfIO_HttpProcessResponse(int sfd, const char** appStrList,
/* handle incomplete rx */ /* handle incomplete rx */
if (end == NULL) { if (end == NULL) {
if (len != 0) if (len != 0)
XMEMMOVE(httpBuf, start, len); XMEMMOVE(httpBuf, start, (size_t)len);
start = end = NULL; start = end = NULL;
} }
/* when start is "\r\n" */ /* when start is "\r\n" */
@ -1755,7 +1755,7 @@ int wolfIO_HttpBuildRequest(const char *reqType, const char *domainName,
return wolfIO_HttpBuildRequest_ex(reqType, domainName, path, pathLen, reqSz, contentType, "", buf, bufSize); return wolfIO_HttpBuildRequest_ex(reqType, domainName, path, pathLen, reqSz, contentType, "", buf, bufSize);
} }
int wolfIO_HttpBuildRequest_ex(const char *reqType, const char *domainName, int wolfIO_HttpBuildRequest_ex(const char *reqType, const char *domainName,
const char *path, int pathLen, int reqSz, const char *contentType, const char *path, int pathLen, int reqSz, const char *contentType,
const char *exHdrs, byte *buf, int bufSize) const char *exHdrs, byte *buf, int bufSize)
{ {
@ -1797,7 +1797,7 @@ int wolfIO_HttpBuildRequest(const char *reqType, const char *domainName,
maxLen = maxLen =
reqTypeLen + reqTypeLen +
blankStrLen + blankStrLen +
pathLen + (word32)pathLen +
http11StrLen + http11StrLen +
hostStrLen + hostStrLen +
domainNameLen + domainNameLen +
@ -1808,46 +1808,46 @@ int wolfIO_HttpBuildRequest(const char *reqType, const char *domainName,
singleCrLfStrLen + singleCrLfStrLen +
exHdrsLen + exHdrsLen +
doubleCrLfStrLen + doubleCrLfStrLen +
1 /* null term */; (word32)1 /* null term */;
if (maxLen > (word32)bufSize) if (maxLen > (word32)bufSize)
return 0; return 0;
XSTRNCPY((char*)buf, reqType, bufSize); XSTRNCPY((char*)buf, reqType, (size_t)bufSize);
buf += reqTypeLen; bufSize -= reqTypeLen; buf += reqTypeLen; bufSize -= (int)reqTypeLen;
XSTRNCPY((char*)buf, blankStr, bufSize); XSTRNCPY((char*)buf, blankStr, (size_t)bufSize);
buf += blankStrLen; bufSize -= blankStrLen; buf += blankStrLen; bufSize -= (int)blankStrLen;
XSTRNCPY((char*)buf, path, bufSize); XSTRNCPY((char*)buf, path, (size_t)bufSize);
buf += pathLen; bufSize -= pathLen; buf += pathLen; bufSize -= (int)pathLen;
XSTRNCPY((char*)buf, http11Str, bufSize); XSTRNCPY((char*)buf, http11Str, (size_t)bufSize);
buf += http11StrLen; bufSize -= http11StrLen; buf += http11StrLen; bufSize -= (int)http11StrLen;
if (domainNameLen > 0) { if (domainNameLen > 0) {
XSTRNCPY((char*)buf, hostStr, bufSize); XSTRNCPY((char*)buf, hostStr, (size_t)bufSize);
buf += hostStrLen; bufSize -= hostStrLen; buf += hostStrLen; bufSize -= (int)hostStrLen;
XSTRNCPY((char*)buf, domainName, bufSize); XSTRNCPY((char*)buf, domainName, (size_t)bufSize);
buf += domainNameLen; bufSize -= domainNameLen; buf += domainNameLen; bufSize -= (int)domainNameLen;
} }
if (reqSz > 0 && reqSzStrLen > 0) { if (reqSz > 0 && reqSzStrLen > 0) {
XSTRNCPY((char*)buf, contentLenStr, bufSize); XSTRNCPY((char*)buf, contentLenStr, (size_t)bufSize);
buf += contentLenStrLen; bufSize -= contentLenStrLen; buf += contentLenStrLen; bufSize -= (int)contentLenStrLen;
XSTRNCPY((char*)buf, reqSzStr, bufSize); XSTRNCPY((char*)buf, reqSzStr, (size_t)bufSize);
buf += reqSzStrLen; bufSize -= reqSzStrLen; buf += reqSzStrLen; bufSize -= (int)reqSzStrLen;
} }
if (contentTypeLen > 0) { if (contentTypeLen > 0) {
XSTRNCPY((char*)buf, contentTypeStr, bufSize); XSTRNCPY((char*)buf, contentTypeStr, (size_t)bufSize);
buf += contentTypeStrLen; bufSize -= contentTypeStrLen; buf += contentTypeStrLen; bufSize -= (int)contentTypeStrLen;
XSTRNCPY((char*)buf, contentType, bufSize); XSTRNCPY((char*)buf, contentType, (size_t)bufSize);
buf += contentTypeLen; bufSize -= contentTypeLen; buf += contentTypeLen; bufSize -= (int)contentTypeLen;
} }
if (exHdrsLen > 0) if (exHdrsLen > 0)
{ {
XSTRNCPY((char *)buf, singleCrLfStr, bufSize); XSTRNCPY((char *)buf, singleCrLfStr, (size_t)bufSize);
buf += singleCrLfStrLen; buf += singleCrLfStrLen;
bufSize -= singleCrLfStrLen; bufSize -= (int)singleCrLfStrLen;
XSTRNCPY((char *)buf, exHdrs, bufSize); XSTRNCPY((char *)buf, exHdrs, (size_t)bufSize);
buf += exHdrsLen; buf += exHdrsLen;
bufSize -= exHdrsLen; bufSize -= (int)exHdrsLen;
} }
XSTRNCPY((char*)buf, doubleCrLfStr, bufSize); XSTRNCPY((char*)buf, doubleCrLfStr, (size_t)bufSize);
buf += doubleCrLfStrLen; buf += doubleCrLfStrLen;
#ifdef WOLFIO_DEBUG #ifdef WOLFIO_DEBUG
@ -1924,7 +1924,7 @@ int EmbedOcspLookup(void* ctx, const char* url, int urlSz,
/* Note, the library uses the EmbedOcspRespFree() callback to /* Note, the library uses the EmbedOcspRespFree() callback to
* free this buffer. */ * free this buffer. */
int httpBufSz = HTTP_SCRATCH_BUFFER_SIZE; int httpBufSz = HTTP_SCRATCH_BUFFER_SIZE;
byte* httpBuf = (byte*)XMALLOC(httpBufSz, ctx, DYNAMIC_TYPE_OCSP); byte* httpBuf = (byte*)XMALLOC((size_t)httpBufSz, ctx, DYNAMIC_TYPE_OCSP);
if (httpBuf == NULL) { if (httpBuf == NULL) {
WOLFSSL_MSG("Unable to create OCSP response buffer"); WOLFSSL_MSG("Unable to create OCSP response buffer");
@ -2031,7 +2031,7 @@ int EmbedCrlLookup(WOLFSSL_CRL* crl, const char* url, int urlSz)
} }
else { else {
int httpBufSz = HTTP_SCRATCH_BUFFER_SIZE; int httpBufSz = HTTP_SCRATCH_BUFFER_SIZE;
byte* httpBuf = (byte*)XMALLOC(httpBufSz, crl->heap, byte* httpBuf = (byte*)XMALLOC((size_t)httpBufSz, crl->heap,
DYNAMIC_TYPE_CRL); DYNAMIC_TYPE_CRL);
if (httpBuf == NULL) { if (httpBuf == NULL) {
WOLFSSL_MSG("Unable to create CRL response buffer"); WOLFSSL_MSG("Unable to create CRL response buffer");