Skip to content

Commit

Permalink
Additional conversion warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgarske committed Nov 27, 2024
1 parent 81ae002 commit 2d7de44
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 69 deletions.
4 changes: 2 additions & 2 deletions src/bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ 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, bio->wrSz + len, 0)
if (wolfSSL_BUF_MEM_grow_ex(bio->mem_buf, (size_t)(bio->wrSz + len), 0)
== 0) {
WOLFSSL_MSG("Error growing memory area");
return WOLFSSL_FAILURE;
Expand Down Expand Up @@ -1320,7 +1320,7 @@ 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 pair->wrSz - pair->rdIdx + pair->wrIdx;
return (size_t)(pair->wrSz - pair->rdIdx + pair->wrIdx);
}
else {
/* simple case where has not wrapped around */
Expand Down
13 changes: 7 additions & 6 deletions src/pk.c
Original file line number Diff line number Diff line change
Expand Up @@ -5630,7 +5630,8 @@ static int dsa_do_verify(const unsigned char* d, int dLen, unsigned char* sig,
ret = dLen == WC_SHA_DIGEST_SIZE ?
wc_DsaVerify(d, sig, (DsaKey*)dsa->internal, dsacheck) : BAD_FUNC_ARG;
#else
ret = wc_DsaVerify_ex(d, dLen, sig, (DsaKey*)dsa->internal, dsacheck);
ret = wc_DsaVerify_ex(d, (word32)dLen, sig, (DsaKey*)dsa->internal,
dsacheck);
#endif
if (ret != 0) {
WOLFSSL_MSG("DsaVerify failed");
Expand Down Expand Up @@ -9475,24 +9476,24 @@ int wolfSSL_i2d_ECPKParameters(const WOLFSSL_EC_GROUP* grp, unsigned char** pp)

/* Get the actual DER encoding of the OID. ecc_sets[grp->curve_idx].oid
* is just the numerical representation. */
if (wc_ecc_get_oid(grp->curve_oid, &oid, &oidSz) < 0)
if (wc_ecc_get_oid((word32)grp->curve_oid, &oid, &oidSz) < 0)
return WOLFSSL_FATAL_ERROR;

len = SetObjectId(oidSz, NULL) + oidSz;
len = SetObjectId((int)oidSz, NULL) + (int)oidSz;

if (pp == NULL)
return len;

if (*pp == NULL) {
out = (unsigned char*)XMALLOC(len, NULL, DYNAMIC_TYPE_ASN1);
out = (unsigned char*)XMALLOC((size_t)len, NULL, DYNAMIC_TYPE_ASN1);
if (out == NULL)
return WOLFSSL_FATAL_ERROR;
}
else {
out = *pp;
}

idx = SetObjectId(oidSz, out);
idx = SetObjectId((int)oidSz, out);
XMEMCPY(out + idx, oid, oidSz);
if (*pp == NULL)
*pp = out;
Expand Down Expand Up @@ -16537,7 +16538,7 @@ int pkcs8_encode(WOLFSSL_EVP_PKEY* pkey, byte* key, word32* keySz)
if (keySz == NULL)
return BAD_FUNC_ARG;

*keySz = pkey->pkey_sz;
*keySz = (word32)pkey->pkey_sz;
if (key == NULL)
return LENGTH_ONLY_E;

Expand Down
8 changes: 4 additions & 4 deletions src/ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -7363,16 +7363,16 @@ WOLFSSL_PKCS8_PRIV_KEY_INFO* wolfSSL_d2i_PKCS8_PKEY(
pkcs8Der->length, &algId);
if (ret >= 0) {
if (advanceLen == 0) /* Set only if not PEM */
advanceLen = inOutIdx + ret;
advanceLen = (int)inOutIdx + ret;
if (algId == DHk) {
/* Special case for DH as we expect the DER buffer to be always
* be in PKCS8 format */
rawDer.buffer = pkcs8Der->buffer;
rawDer.length = inOutIdx + ret;
rawDer.length = inOutIdx + (word32)ret;
}
else {
rawDer.buffer = pkcs8Der->buffer + inOutIdx;
rawDer.length = ret;
rawDer.length = (word32)ret;
}
ret = 0; /* good DER */
}
Expand Down Expand Up @@ -7434,7 +7434,7 @@ int wolfSSL_i2d_PKCS8_PKEY(WOLFSSL_PKCS8_PRIV_KEY_INFO* key, unsigned char** pp)
return len;

if (*pp == NULL) {
out = (unsigned char*)XMALLOC(len, NULL, DYNAMIC_TYPE_ASN1);
out = (unsigned char*)XMALLOC((size_t)len, NULL, DYNAMIC_TYPE_ASN1);
if (out == NULL)
return WOLFSSL_FATAL_ERROR;
}
Expand Down
10 changes: 5 additions & 5 deletions src/tls13.c
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ int Tls13_Exporter(WOLFSSL* ssl, unsigned char *out, size_t outLen,
ret = Tls13HKDFExpandLabel(ssl, firstExpand, hashLen,
ssl->arrays->exporterSecret, hashLen,
protocol, protocolLen, (byte*)label, (word32)labelLen,
emptyHash, hashLen, hashType);
emptyHash, hashLen, (int)hashType);
if (ret != 0)
return ret;

Expand All @@ -1035,7 +1035,7 @@ int Tls13_Exporter(WOLFSSL* ssl, unsigned char *out, size_t outLen,

ret = Tls13HKDFExpandLabel(ssl, out, (word32)outLen, firstExpand, hashLen,
protocol, protocolLen, exporterLabel, EXPORTER_LABEL_SZ,
hashOut, hashLen, hashType);
hashOut, hashLen, (int)hashType);

return ret;
}
Expand Down Expand Up @@ -8434,7 +8434,7 @@ static word32 NextCert(byte* data, word32 length, word32* idx)
* offset index offset
* returns Total number of bytes written.
*/
static word32 WriteCSRToBuffer(WOLFSSL* ssl, DerBuffer** certExts,
static int WriteCSRToBuffer(WOLFSSL* ssl, DerBuffer** certExts,
word16* extSz, word16 extSz_num)
{
int ret = 0;
Expand All @@ -8452,7 +8452,7 @@ static word32 WriteCSRToBuffer(WOLFSSL* ssl, DerBuffer** certExts,

if (csr) {
for (extIdx = 0; extIdx < (word16)(extSz_num); extIdx++) {
tmpSz = TLSX_CSR_GetSize_ex(csr, 0, extIdx);
tmpSz = TLSX_CSR_GetSize_ex(csr, 0, (int)extIdx);

if (tmpSz > (OPAQUE8_LEN + OPAQUE24_LEN) &&
certExts[extIdx] == NULL) {
Expand Down Expand Up @@ -8487,7 +8487,7 @@ static word32 WriteCSRToBuffer(WOLFSSL* ssl, DerBuffer** certExts,
/* chain cert empty extension size */
totalSz += OPAQUE16_LEN * extSz_num;
}
return totalSz;
return (int)totalSz;
}
#endif /* HAVE_CERTIFICATE_STATUS_REQUEST */
/* Add certificate data and empty extension to output up to the fragment size.
Expand Down
62 changes: 32 additions & 30 deletions src/x509.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ int wolfSSL_X509_get_ext_count(const WOLFSSL_X509* passedCert)
FreeDecodedCert(cert);
return WOLFSSL_FAILURE;
}
idx += length;
idx += (word32)length;
extCount++;
}

Expand Down Expand Up @@ -516,8 +516,8 @@ static int wolfssl_dns_entry_othername_to_gn(DNS_entry* dns,
const unsigned char* oid;
word32 oidSz;

if ((oid = OidFromId(dns->oidSum, oidCertAltNameType, &oidSz)) ==
NULL) {
if ((oid = OidFromId((word32)dns->oidSum, oidCertAltNameType,
&oidSz)) == NULL) {
if (dns->oidSum == UPN_OID) {
oid = upn_oid;
oidSz = (word32)sizeof(upn_oid);
Expand Down Expand Up @@ -633,15 +633,16 @@ static int DNS_to_GENERAL_NAME(WOLFSSL_GENERAL_NAME* gn, DNS_entry* dns)
if (gn->d.registeredID == NULL) {
return WOLFSSL_FAILURE;
}
gn->d.registeredID->obj = (const unsigned char*)XMALLOC(dns->len,
gn->d.registeredID->obj = (const unsigned char*)XMALLOC(
(size_t)dns->len,
gn->d.registeredID->heap, DYNAMIC_TYPE_ASN1);
if (gn->d.registeredID->obj == NULL) {
/* registeredID gets free'd up by caller after failure */
return WOLFSSL_FAILURE;
}
gn->d.registeredID->dynamic |= WOLFSSL_ASN1_DYNAMIC_DATA;
XMEMCPY((byte*)gn->d.registeredID->obj, dns->ridString, dns->len);
gn->d.registeredID->objSz = dns->len;
gn->d.registeredID->objSz = (unsigned int)dns->len;
gn->d.registeredID->grp = oidCertExtType;
gn->d.registeredID->nid = WC_NID_registeredAddress;
break;
Expand Down Expand Up @@ -669,7 +670,7 @@ static int wolfssl_x509_alt_names_to_gn(WOLFSSL_X509* x509,

#ifdef OPENSSL_ALL
ret = wolfSSL_ASN1_STRING_set(&ext->value, x509->subjAltNameSrc,
x509->subjAltNameSz);
(int)x509->subjAltNameSz);
if (ret != WOLFSSL_SUCCESS) {
WOLFSSL_MSG("ASN1_STRING_set() failed");
goto err;
Expand Down Expand Up @@ -869,7 +870,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)

/* Continue while loop until extCount == loc or idx > sz */
if (extCount != loc) {
idx += length;
idx += (word32)length;
extCount++;
continue;
}
Expand Down Expand Up @@ -914,8 +915,9 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
/* Skip the critical information */
if (input[dataIdx] == ASN_BOOLEAN) {
dataIdx++;
ret = GetLength(input, &dataIdx, &dataLen, sz) >= 0;
dataIdx += dataLen;
ret = GetLength(input, &dataIdx, &dataLen,
(word32)sz) >= 0;
dataIdx += (word32)dataLen;
}
}
if (ret) {
Expand Down Expand Up @@ -1041,7 +1043,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
break;

ret = wolfSSL_ASN1_STRING_set(&ext->value, x509->authKeyId,
x509->authKeyIdSz);
(int)x509->authKeyIdSz);
if (ret != WOLFSSL_SUCCESS) {
WOLFSSL_MSG("ASN1_STRING_set() failed");
wolfSSL_X509_EXTENSION_free(ext);
Expand All @@ -1059,7 +1061,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
break;

ret = wolfSSL_ASN1_STRING_set(&ext->value, x509->subjKeyId,
x509->subjKeyIdSz);
(int)x509->subjKeyIdSz);
if (ret != WOLFSSL_SUCCESS) {
WOLFSSL_MSG("ASN1_STRING_set() failed");
wolfSSL_X509_EXTENSION_free(ext);
Expand Down Expand Up @@ -1103,7 +1105,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
break;

ret = wolfSSL_ASN1_STRING_set(&ext->value, x509->extKeyUsageSrc,
x509->extKeyUsageSz);
(int)x509->extKeyUsageSz);
if (ret != WOLFSSL_SUCCESS) {
WOLFSSL_MSG("ASN1_STRING_set() failed");
wolfSSL_X509_EXTENSION_free(ext);
Expand Down Expand Up @@ -1151,7 +1153,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
#endif
return NULL;
}
oidBuf = (byte*)XMALLOC(length+1+MAX_LENGTH_SZ, NULL,
oidBuf = (byte*)XMALLOC((size_t)length+1+MAX_LENGTH_SZ, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (oidBuf == NULL) {
WOLFSSL_MSG("Failed to malloc tmp buffer");
Expand All @@ -1164,7 +1166,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
}
oidBuf[0] = ASN_OBJECT_ID;
objSz++;
objSz += SetLength(length, oidBuf + 1);
objSz += SetLength((word32)length, oidBuf + 1);
objSz += length;

/* Set object size and reallocate space in object buffer */
Expand Down Expand Up @@ -1210,7 +1212,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
ext->crit = 0;

/* Get extension data and copy as ASN1_STRING */
tmpIdx = idx + length;
tmpIdx = idx + (word32)length;
if ((tmpIdx >= (word32)sz) ||
(input[tmpIdx] != ASN_OCTET_STRING))
{
Expand All @@ -1236,7 +1238,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
#endif
return NULL;
}
ext->value.data = (char*)XMALLOC(length, NULL,
ext->value.data = (char*)XMALLOC((size_t)length, NULL,
DYNAMIC_TYPE_ASN1);
ext->value.isDynamic = 1;
if (ext->value.data == NULL) {
Expand Down Expand Up @@ -1287,7 +1289,7 @@ static int asn1_string_copy_to_buffer(WOLFSSL_ASN1_STRING* str, byte** buf,
if (*buf)
XFREE(*buf, heap, DYNAMIC_TYPE_X509_EXT);
*len = 0;
*buf = (byte*)XMALLOC(str->length, heap, DYNAMIC_TYPE_X509_EXT);
*buf = (byte*)XMALLOC((size_t)str->length, heap, DYNAMIC_TYPE_X509_EXT);
if (!*buf) {
WOLFSSL_MSG("malloc error");
return WOLFSSL_FAILURE;
Expand Down Expand Up @@ -1371,7 +1373,7 @@ int wolfSSL_X509_add_ext(WOLFSSL_X509 *x509, WOLFSSL_X509_EXTENSION *ext,
}
else if (!gn || !gn->d.ia5 ||
wolfSSL_X509_add_altname_ex(x509, gn->d.ia5->data,
gn->d.ia5->length, gn->type) != WOLFSSL_SUCCESS) {
(word32)gn->d.ia5->length, gn->type) != WOLFSSL_SUCCESS) {
WOLFSSL_MSG("Subject alternative name missing extension");
return WOLFSSL_FAILURE;
}
Expand Down Expand Up @@ -1458,7 +1460,7 @@ int wolfSSL_X509_add_ext(WOLFSSL_X509 *x509, WOLFSSL_X509_EXTENSION *ext,
/* This is a viable custom extension. */
oid = (char*)XMALLOC(MAX_OID_STRING_SZ, x509->heap,
DYNAMIC_TYPE_X509_EXT);
val = (byte*)XMALLOC(ext->value.length, x509->heap,
val = (byte*)XMALLOC((size_t)ext->value.length, x509->heap,
DYNAMIC_TYPE_X509_EXT);
if ((oid == NULL) || (val == NULL)) {
WOLFSSL_MSG("Memory allocation failure.\n");
Expand Down Expand Up @@ -1820,7 +1822,7 @@ static WOLFSSL_AUTHORITY_INFO_ACCESS* wolfssl_x509v3_ext_aia_d2i(

/* Set the URI into GENERAL_NAME. */
ret = wolfSSL_ASN1_STRING_set(ad->location->d.uniformResourceIdentifier,
aiaEntry->obj, aiaEntry->objSz);
aiaEntry->obj, (int)aiaEntry->objSz);
if (ret != WOLFSSL_SUCCESS) {
WOLFSSL_MSG("ASN1_STRING_set() failed");
err = 1;
Expand Down Expand Up @@ -2167,7 +2169,7 @@ int wolfSSL_X509_get_ext_by_NID(const WOLFSSL_X509* x509, int nid, int lastPos)
}
}

idx += length;
idx += (word32)length;
extCount++;
} /* while(idx < sz) */

Expand Down Expand Up @@ -2291,13 +2293,13 @@ void* wolfSSL_X509_get_ext_d2i(const WOLFSSL_X509* x509, int nid, int* c,
{
int localIdx = 0;
unsigned char* n = (unsigned char*)XMALLOC(
dns->len + MAX_SEQ_SZ, x509->heap,
DYNAMIC_TYPE_TMP_BUFFER);
(size_t)dns->len + MAX_SEQ_SZ, x509->heap,
DYNAMIC_TYPE_TMP_BUFFER);
if (n == NULL) {
goto err;
}

localIdx += SetSequence(dns->len, n);
localIdx += SetSequence((word32)dns->len, n);
XMEMCPY(n + localIdx, dns->name, dns->len);
gn->d.dirn = wolfSSL_d2i_X509_NAME(NULL, &n,
dns->len + localIdx);
Expand Down Expand Up @@ -3023,7 +3025,7 @@ WOLFSSL_X509_EXTENSION *wolfSSL_X509V3_EXT_i2d(int nid, int crit,
asn1str = (WOLFSSL_ASN1_STRING*)data;
ext->value = *asn1str;
if (asn1str->isDynamic) {
ext->value.data = (char*)XMALLOC(asn1str->length, NULL,
ext->value.data = (char*)XMALLOC((size_t)asn1str->length, NULL,
DYNAMIC_TYPE_OPENSSL);
if (!ext->value.data) {
WOLFSSL_MSG("malloc failed");
Expand Down Expand Up @@ -3232,8 +3234,8 @@ int wolfSSL_X509_digest(const WOLFSSL_X509* x509, const WOLFSSL_EVP_MD* digest,
return WOLFSSL_FAILURE;
}

ret = wolfSSL_EVP_Digest(x509->derCert->buffer, x509->derCert->length, buf,
len, digest, NULL);
ret = wolfSSL_EVP_Digest(x509->derCert->buffer,
(int)x509->derCert->length, buf, len, digest, NULL);
WOLFSSL_LEAVE("wolfSSL_X509_digest", ret);
return ret;
}
Expand Down Expand Up @@ -3365,7 +3367,7 @@ char* wolfSSL_X509_NAME_oneline(WOLFSSL_X509_NAME* name, char* in, int sz)
WOLFSSL_MSG("Using static memory -- please pass in a buffer");
return NULL;
#else
in = (char*)XMALLOC(name->sz, NULL, DYNAMIC_TYPE_OPENSSL);
in = (char*)XMALLOC((size_t)name->sz, NULL, DYNAMIC_TYPE_OPENSSL);
if (!in)
return in;
copySz = name->sz;
Expand Down Expand Up @@ -3557,7 +3559,7 @@ char* wolfSSL_X509_get_name_oneline(WOLFSSL_X509_NAME* name, char* in, int sz)
*/
if (i != count - 1) {
strSz = (int)XSTRLEN(sn) + nameSz + 4;
str = (char*)XMALLOC(strSz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
str = (char*)XMALLOC((size_t)strSz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (str == NULL) {
WOLFSSL_MSG("Memory error");
return NULL;
Expand All @@ -3575,7 +3577,7 @@ char* wolfSSL_X509_get_name_oneline(WOLFSSL_X509_NAME* name, char* in, int sz)
* Add extra strSz for '=' and '\0' characters in XSNPRINTF.
*/
strSz = (int)XSTRLEN(sn) + nameSz + 2;
str = (char*)XMALLOC(strSz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
str = (char*)XMALLOC((size_t)strSz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (str == NULL) {
WOLFSSL_MSG("Memory error");
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion tests/quic.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ static int ctx_send_alert(WOLFSSL *ssl, WOLFSSL_ENCRYPTION_LEVEL level, uint8_t
if (ctx->verbose) {
printf("[%s] send_alert: level=%d, err=%d\n", ctx->name, level, err);
}
ctx->alert_level = level;
ctx->alert_level = (int)level;
ctx->alert = alert;
return 1;
}
Expand Down
Loading

0 comments on commit 2d7de44

Please sign in to comment.