Skip to content

Commit

Permalink
Initialize vars & change types to appease Windows/VS
Browse files Browse the repository at this point in the history
  • Loading branch information
gojimmypi committed Nov 13, 2024
1 parent 878cf3a commit 7791535
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 50 deletions.
5 changes: 4 additions & 1 deletion src/bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1378,8 +1378,11 @@ long wolfSSL_BIO_get_mem_ptr(WOLFSSL_BIO *bio, WOLFSSL_BUF_MEM **ptr)
if (closeFlag == BIO_CLOSE)
wolfSSL_BUF_MEM_free(bio->mem_buf);

if ((closeFlag < 0) || (closeFlag > 255)) {
return BAD_FUNC_ARG;
}
bio->mem_buf = bufMem;
bio->shutdown = closeFlag;
bio->shutdown = (byte)closeFlag;

bio->wrSz = (int)bio->mem_buf->length;
bio->wrSzReset = bio->wrSz;
Expand Down
15 changes: 12 additions & 3 deletions src/dtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
#include <wolfcrypt/src/misc.c>
#endif

#ifndef UINT16_MAX
#define UINT16_MAX 65535
#endif

#define ERROR_OUT(err, eLabel) { ret = (err); goto eLabel; }

#ifdef WOLFSSL_DTLS
Expand Down Expand Up @@ -716,9 +720,14 @@ static int SendStatelessReplyDtls13(const WOLFSSL* ssl, WolfSSL_CH* ch)
* and if they don't match we will error out there anyway. */
byte modes;

/* TLSX_PreSharedKey_Parse_ClientHello uses word16 length */
if (tlsx.size > UINT16_MAX) {
ERROR_OUT(BUFFER_ERROR, dtls13_cleanup);
}

/* Ask the user for the ciphersuite matching this identity */
if (TLSX_PreSharedKey_Parse_ClientHello(&parsedExts,
tlsx.elements, tlsx.size, ssl->heap) == 0)
tlsx.elements, (word16)tlsx.size, ssl->heap) == 0)
FindPskSuiteFromExt(ssl, parsedExts, &pskInfo, &suites);
/* Revert to full handshake if PSK parsing failed */

Expand All @@ -729,8 +738,8 @@ static int SendStatelessReplyDtls13(const WOLFSSL* ssl, WolfSSL_CH* ch)
goto dtls13_cleanup;
if (!tlsxFound)
ERROR_OUT(PSK_KEY_ERROR, dtls13_cleanup);
ret = TLSX_PskKeyModes_Parse_Modes(tlsx.elements, tlsx.size,
client_hello, &modes);
ret = TLSX_PskKeyModes_Parse_Modes(tlsx.elements, (word16)tlsx.size,
client_hello, &modes);
if (ret != 0)
goto dtls13_cleanup;
if ((modes & (1 << PSK_DHE_KE)) &&
Expand Down
10 changes: 5 additions & 5 deletions src/pk.c
Original file line number Diff line number Diff line change
Expand Up @@ -3562,7 +3562,7 @@ int wolfSSL_RSA_padding_add_PKCS1_PSS_mgf1(WOLFSSL_RSA *rsa, unsigned char *em,
const WOLFSSL_EVP_MD *mgf1Hash, int saltLen)
{
int ret = 1;
enum wc_HashType hashType;
enum wc_HashType hashType = WC_HASH_TYPE_NONE;
int hashLen = 0;
int emLen = 0;
int mgf = 0;
Expand Down Expand Up @@ -7876,7 +7876,7 @@ static int wolfssl_dhparams_to_der(WOLFSSL_DH* dh, unsigned char** out,
int ret = WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR);
int err = 0;
byte* der = NULL;
word32 derSz;
word32 derSz = 0;
DhKey* key = NULL;

(void)heap;
Expand Down Expand Up @@ -7933,7 +7933,7 @@ static int wolfssl_dhparams_to_der(WOLFSSL_DH* dh, unsigned char** out,
int wolfSSL_PEM_write_DHparams(XFILE fp, WOLFSSL_DH* dh)
{
int ret = 1;
int derSz;
int derSz = 0;
byte* derBuf = NULL;
void* heap = NULL;

Expand Down Expand Up @@ -16501,7 +16501,7 @@ int pkcs8_encode(WOLFSSL_EVP_PKEY* pkey, byte* key, word32* keySz)
{
int ret = 0;
int algId = 0;
const byte* curveOid;
const byte* curveOid = 0;
word32 oidSz = 0;

/* Get the details of the private key. */
Expand Down Expand Up @@ -16587,7 +16587,7 @@ static int pem_write_mem_pkcs8privatekey(byte** pem, int* pemSz,
int ret = 0;
char password[NAME_SZ];
byte* key = NULL;
word32 keySz;
word32 keySz =0;
int type = PKCS8_PRIVATEKEY_TYPE;

/* Validate parameters. */
Expand Down
13 changes: 12 additions & 1 deletion src/ssl_asn1.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
#endif
#else

#ifndef UINT8_MAX
#define UINT8_MAX 255
#endif

/*******************************************************************************
* ASN1_item APIs
******************************************************************************/
Expand Down Expand Up @@ -282,10 +286,17 @@ static int wolfssl_i2d_asn1_items(const void* obj, byte* buf,
len = 0;
break;
}

/* SetImplicit allows only 8-but number value */
if (mem->tag > UINT8_MAX) {
len = 0;
break;
}

if (buf != NULL && tmp != NULL && !mem->ex && mem->tag >= 0) {
/* Encode the implicit tag */
byte imp[ASN_TAG_SZ + MAX_LENGTH_SZ];
SetImplicit(tmp[0], mem->tag, 0, imp, 0);
SetImplicit(tmp[0], (byte)mem->tag, 0, imp, 0);
tmp[0] = imp[0];
}
len += ret;
Expand Down
2 changes: 1 addition & 1 deletion src/ssl_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -5023,7 +5023,7 @@ int wolfSSL_CTX_use_certificate_ASN1(WOLFSSL_CTX *ctx, int derSz,
int wolfSSL_CTX_use_RSAPrivateKey(WOLFSSL_CTX* ctx, WOLFSSL_RSA* rsa)
{
int ret = 1;
int derSize;
int derSize = 0;
unsigned char* der = NULL;
unsigned char* p;

Expand Down
2 changes: 1 addition & 1 deletion src/ssl_p7p12.c
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ int wolfSSL_PEM_write_bio_PKCS7(WOLFSSL_BIO* bio, PKCS7* p7)
int pemSz = -1;
enum wc_HashType hashType;
byte hashBuf[WC_MAX_DIGEST_SIZE];
word32 hashSz = -1;
word32 hashSz = 0;

WOLFSSL_ENTER("wolfSSL_PEM_write_bio_PKCS7");

Expand Down
15 changes: 12 additions & 3 deletions src/ssl_sess.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@

#include <wolfssl/wolfcrypt/settings.h>

#ifndef UINT8_MAX
#define UINT8_MAX 255
#endif

#if !defined(WOLFSSL_SSL_SESS_INCLUDED)
#ifndef WOLFSSL_IGNORE_FILE_WARN
#warning ssl_sess.c does not need to be compiled separately from ssl.c
Expand Down Expand Up @@ -3748,7 +3752,7 @@ static int wolfSSL_DupSessionEx(const WOLFSSL_SESSION* input,
byte* ticketNonceLen, byte* preallocUsed)
{
#ifdef HAVE_SESSION_TICKET
int ticLenAlloc = 0;
word16 ticLenAlloc = 0;
byte *ticBuff = NULL;
#endif
const size_t copyOffset = OFFSETOF(WOLFSSL_SESSION, heap) +
Expand Down Expand Up @@ -4164,7 +4168,12 @@ int wolfSSL_SESSION_set1_id(WOLFSSL_SESSION *s,
if (sid_len > ID_LEN) {
return WOLFSSL_FAILURE;
}
s->sessionIDSz = sid_len;

if (sid_len > UINT8_MAX) {
return WOLFSSL_FAILURE;
}

s->sessionIDSz = (byte)sid_len;
if (sid != s->sessionID) {
XMEMCPY(s->sessionID, sid, sid_len);
}
Expand All @@ -4180,7 +4189,7 @@ int wolfSSL_SESSION_set1_id_context(WOLFSSL_SESSION *s,
if (sid_ctx_len > ID_LEN) {
return WOLFSSL_FAILURE;
}
s->sessionCtxSz = sid_ctx_len;
s->sessionCtxSz = (byte)sid_ctx_len;
if (sid_ctx != s->sessionCtx) {
XMEMCPY(s->sessionCtx, sid_ctx, sid_ctx_len);
}
Expand Down
34 changes: 24 additions & 10 deletions src/tls13.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@
#include <wolfssl/wolfcrypt/wc_port.h>
#endif

#ifndef UINT16_MAX
#define UINT16_MAX 65535
#endif

#ifndef WOLFCRYPT_ONLY

#ifdef HAVE_ERRNO_H
Expand Down Expand Up @@ -4018,6 +4022,10 @@ static int WritePSKBinders(WOLFSSL* ssl, byte* output, word32 idx)

WOLFSSL_ENTER("WritePSKBinders");

if (idx > UINT16_MAX) {
return INPUT_SIZE_E;
}

ext = TLSX_Find(ssl->extensions, TLSX_PRE_SHARED_KEY);
if (ext == NULL)
return SANITY_MSG_E;
Expand All @@ -4033,7 +4041,7 @@ static int WritePSKBinders(WOLFSSL* ssl, byte* output, word32 idx)
#ifdef WOLFSSL_DTLS13
if (ssl->options.dtls)
ret = Dtls13HashHandshake(ssl, output + Dtls13GetRlHeaderLength(ssl, 0),
idx - Dtls13GetRlHeaderLength(ssl, 0));
(word16)idx - Dtls13GetRlHeaderLength(ssl, 0));
else
#endif /* WOLFSSL_DTLS13 */
ret = HashOutput(ssl, output, (int)idx, 0);
Expand Down Expand Up @@ -6270,7 +6278,7 @@ static int CheckPreSharedKeys(WOLFSSL* ssl, const byte* input, word32 helloSz,
return ret;

if (*usingPSK != 0) {
word16 modes;
word32 modes;
#ifdef WOLFSSL_EARLY_DATA
TLSX* extEarlyData;

Expand Down Expand Up @@ -10856,14 +10864,18 @@ int DoTls13Finished(WOLFSSL* ssl, const byte* input, word32* inOutIdx,

if (sniff == NO_SNIFF) {
ret = BuildTls13HandshakeHmac(ssl, secret, mac, &finishedSz);

if (finishedSz > 255) {
return BUFFER_ERROR;
}
#ifdef WOLFSSL_HAVE_TLS_UNIQUE
if (ssl->options.side == WOLFSSL_CLIENT_END) {
XMEMCPY(ssl->serverFinished, mac, finishedSz);
ssl->serverFinished_len = finishedSz;
ssl->serverFinished_len = (byte)finishedSz;
}
else {
XMEMCPY(ssl->clientFinished, mac, finishedSz);
ssl->clientFinished_len = finishedSz;
ssl->clientFinished_len = (byte)finishedSz;
}
#endif /* WOLFSSL_HAVE_TLS_UNIQUE */
if (ret != 0)
Expand Down Expand Up @@ -10945,7 +10957,7 @@ int DoTls13Finished(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
*/
static int SendTls13Finished(WOLFSSL* ssl)
{
int finishedSz = ssl->specs.hash_size;
byte finishedSz = ssl->specs.hash_size;
byte* input;
byte* output;
int ret;
Expand Down Expand Up @@ -11805,10 +11817,10 @@ static int SendTls13NewSessionTicket(WOLFSSL* ssl)
{
byte* output;
int ret;
word32 length;
int sendSz;
word16 extSz;
word32 length;
word32 idx = RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ;
word16 idx = RECORD_HEADER_SZ + HANDSHAKE_HEADER_SZ;

WOLFSSL_START(WC_FUNC_NEW_SESSION_TICKET_SEND);
WOLFSSL_ENTER("SendTls13NewSessionTicket");
Expand Down Expand Up @@ -11878,7 +11890,7 @@ static int SendTls13NewSessionTicket(WOLFSSL* ssl)
/* Nonce */
length += TICKET_NONCE_LEN_SZ + DEF_TICKET_NONCE_SZ;

sendSz = (int)(idx + length + MAX_MSG_EXTRA);
sendSz = (word16)(idx + length + MAX_MSG_EXTRA);

/* Check buffers are big enough and grow if needed. */
if ((ret = CheckAvailableSize(ssl, sendSz)) != 0)
Expand Down Expand Up @@ -11946,11 +11958,13 @@ static int SendTls13NewSessionTicket(WOLFSSL* ssl)

#ifdef WOLFSSL_DTLS13
if (ssl->options.dtls)
return Dtls13HandshakeSend(ssl, output, sendSz, idx, session_ticket, 0);
return Dtls13HandshakeSend(ssl, output, (word16)sendSz,
idx, session_ticket, 0);
#endif /* WOLFSSL_DTLS13 */

/* This message is always encrypted. */
sendSz = BuildTls13Message(ssl, output, sendSz, output + RECORD_HEADER_SZ,
sendSz = BuildTls13Message(ssl, output, sendSz,
output + RECORD_HEADER_SZ,
idx - RECORD_HEADER_SZ, handshake, 0, 0, 0);
if (sendSz < 0)
return sendSz;
Expand Down
10 changes: 9 additions & 1 deletion src/x509.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@

#include <wolfssl/wolfcrypt/settings.h>

#ifndef UINT16_MAX
#define UINT16_MAX 65535
#endif

#if !defined(WOLFSSL_X509_INCLUDED)
#ifndef WOLFSSL_IGNORE_FILE_WARN
#warning x509.c does not need to be compiled separately from ssl.c
Expand Down Expand Up @@ -1471,9 +1475,13 @@ int wolfSSL_X509_add_ext(WOLFSSL_X509 *x509, WOLFSSL_X509_EXTENSION *ext, int lo
return WOLFSSL_FAILURE;
}

if (ext->crit < 0 || ext->crit > UINT16_MAX) {
return WOLFSSL_FAILURE;
}

/* x509->custom_exts now owns the buffers and they must be managed. */
x509->custom_exts[x509->customExtCount].oid = oid;
x509->custom_exts[x509->customExtCount].crit = ext->crit;
x509->custom_exts[x509->customExtCount].crit = (byte)ext->crit;
x509->custom_exts[x509->customExtCount].val = val;
x509->custom_exts[x509->customExtCount].valSz = ext->value.length;
x509->customExtCount++;
Expand Down
9 changes: 6 additions & 3 deletions wolfcrypt/src/asn.c
Original file line number Diff line number Diff line change
Expand Up @@ -13544,7 +13544,7 @@ static int GenerateDNSEntryIPString(DNS_entry* entry, void* heap)
static int GenerateDNSEntryRIDString(DNS_entry* entry, void* heap)
{
int i, j, ret = 0;
int nameSz = 0;
word16 nameSz = 0;
#if !defined(WOLFCRYPT_ONLY) && defined(OPENSSL_EXTRA)
int nid = 0;
#endif
Expand All @@ -13553,7 +13553,7 @@ static int GenerateDNSEntryRIDString(DNS_entry* entry, void* heap)
word32 idx = 0;
word16 tmpName[MAX_OID_SZ];
char oidName[MAX_OID_SZ];
char* finalName;
char* finalName = NULL;

if (entry == NULL || entry->type != ASN_RID_TYPE) {
return BAD_FUNC_ARG;
Expand Down Expand Up @@ -13611,7 +13611,10 @@ static int GenerateDNSEntryRIDString(DNS_entry* entry, void* heap)
}

if (ret == 0) {
nameSz = (int)XSTRLEN((const char*)finalName);
nameSz = (word16)XSTRLEN((const char*)finalName);
if (nameSz > MAX_OID_SZ) {
return BUFFER_E;
}

entry->ridString = (char*)XMALLOC((word32)(nameSz + 1), heap,
DYNAMIC_TYPE_ALTNAME);
Expand Down
2 changes: 1 addition & 1 deletion wolfcrypt/src/dsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ int wc_MakeDsaKey(WC_RNG *rng, DsaKey *dsa)
return MEMORY_E;
}

SAVE_VECTOR_REGISTERS();
SAVE_VECTOR_REGISTERS(;);

#ifdef WOLFSSL_SMALL_STACK
if ((tmpQ = (mp_int *)XMALLOC(sizeof(*tmpQ), NULL, DYNAMIC_TYPE_WOLF_BIGINT)) == NULL)
Expand Down
Loading

0 comments on commit 7791535

Please sign in to comment.