Skip to content

Commit 11d2679

Browse files
Merge pull request #6601 from SparkiDev/type_conversion_fixes_2
Type conversion fixes: make explicit
2 parents 90b32d7 + 2c96090 commit 11d2679

15 files changed

Lines changed: 1260 additions & 1222 deletions

File tree

examples/asn1/asn1.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ int main(int argc, char* argv[])
329329
/* Default to reading STDIN. */
330330
FILE* fp = stdin;
331331
int file_format = FORMAT_DER;
332-
int indent = 0;
332+
word32 indent = 0;
333333
int pem_skip = 0;
334334

335335
/* Reset options. */
@@ -376,7 +376,7 @@ int main(int argc, char* argv[])
376376
argc--;
377377
argv++;
378378
wc_Asn1PrintOptions_Set(&opts, ASN1_PRINT_OPT_LENGTH,
379-
atoi(argv[0]));
379+
(word32)atoi(argv[0]));
380380
}
381381
/* Do not show text representations of ASN.1 item data. */
382382
else if ((strcmp(argv[0], "-n") == 0) ||
@@ -398,7 +398,7 @@ int main(int argc, char* argv[])
398398
argc--;
399399
argv++;
400400
wc_Asn1PrintOptions_Set(&opts, ASN1_PRINT_OPT_OFFSET,
401-
atoi(argv[0]));
401+
(word32)atoi(argv[0]));
402402
}
403403
/* Show wolfSSL OID value for all OBJECT_IDs. */
404404
else if ((strcmp(argv[0], "-O") == 0) ||

examples/pem/pem.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ static int password_from_userdata(char* passwd, int sz, int rw, void* userdata)
233233
{
234234
(void)rw;
235235
/* Copy user data into buffer. */
236-
strncpy(passwd, (const char*)userdata, sz);
236+
strncpy(passwd, (const char*)userdata, (size_t)sz);
237237
passwd[sz - 1] = '\0';
238238
/* Return length of password returned. */
239239
return (int)XSTRLEN((const char*)passwd);
@@ -397,7 +397,7 @@ static int ConvPemToDer(char* in, word32 offset, word32 len, DerBuffer** der,
397397
/* Remove padding from encryption if requested. */
398398
if ((ret == 0) && padding) {
399399
unsigned char pad = (*der)->buffer[(*der)->length - 1];
400-
int i;
400+
word32 i;
401401

402402
/* Simple padding validation. */
403403
if ((pad == 0) || (pad > (*der)->length)) {
@@ -553,8 +553,8 @@ static int EncryptDer(unsigned char* in, word32 in_len, char* password,
553553
if (ret == 0) {
554554
/* Get length of encrypted DER data. */
555555
ret = wc_CreateEncryptedPKCS8Key(in, in_len, NULL, enc_len, password,
556-
(int)strlen(password), pbe_ver, pbe, enc_alg_id, salt, (int)salt_sz,
557-
iterations, &rng, NULL);
556+
(int)strlen(password), pbe_ver, pbe, enc_alg_id, salt, salt_sz,
557+
(int)iterations, &rng, NULL);
558558
if (ret == LENGTH_ONLY_E) {
559559
ret = 0;
560560
}
@@ -572,8 +572,8 @@ static int EncryptDer(unsigned char* in, word32 in_len, char* password,
572572
if (ret == 0) {
573573
/* Encrypt DER data. */
574574
ret = wc_CreateEncryptedPKCS8Key(in, in_len, *enc, enc_len, password,
575-
(int)strlen(password), pbe_ver, pbe, enc_alg_id, salt, (int)salt_sz,
576-
iterations, &rng, NULL);
575+
(int)strlen(password), pbe_ver, pbe, enc_alg_id, salt, salt_sz,
576+
(int)iterations, &rng, NULL);
577577
if (ret > 0) {
578578
ret = 0;
579579
}
@@ -601,7 +601,7 @@ static int ConvDerToPem(unsigned char* in, word32 offset, word32 len,
601601
{
602602
int ret = 0;
603603
unsigned char* pem = NULL;
604-
int pem_len = 0;
604+
unsigned int pem_len = 0;
605605
/* Set point to start looking and length. */
606606
unsigned char* der = in + offset;
607607
word32 der_len = len - offset;
@@ -611,7 +611,7 @@ static int ConvDerToPem(unsigned char* in, word32 offset, word32 len,
611611
if (ret <= 0) {
612612
fprintf(stderr, "Could not determine length of PEM\n");
613613
}
614-
pem_len = ret;
614+
pem_len = (unsigned int)ret;
615615
if (ret > 0) {
616616
ret = 0;
617617
}
@@ -631,7 +631,7 @@ static int ConvDerToPem(unsigned char* in, word32 offset, word32 len,
631631
}
632632
if (ret > 0) {
633633
*out = pem;
634-
*out_len = ret;
634+
*out_len = (word32)ret;
635635
ret = 0;
636636
}
637637
}

src/ssl_certman.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,16 @@ static WC_INLINE int wolfssl_cm_get_certs_der(WOLFSSL_CERT_MANAGER* cm,
291291

292292
if (!err) {
293293
/* Allocate memory for pointers to each DER buffer. */
294-
certBuffers = (DerBuffer**)XMALLOC(sizeof(DerBuffer*) * numCerts,
295-
cm->heap, DYNAMIC_TYPE_TMP_BUFFER);
294+
certBuffers = (DerBuffer**)XMALLOC(
295+
sizeof(DerBuffer*) * (size_t)numCerts, cm->heap,
296+
DYNAMIC_TYPE_TMP_BUFFER);
296297
if (certBuffers == NULL) {
297298
err = 1;
298299
}
299300
}
300301
if (!err) {
301302
/* Reset pointers. */
302-
XMEMSET(certBuffers, 0, sizeof(DerBuffer*) * numCerts);
303+
XMEMSET(certBuffers, 0, sizeof(DerBuffer*) * (size_t)numCerts);
303304
}
304305

305306
/* Copy the certs locally so that we can release the caLock. If the lock
@@ -382,7 +383,7 @@ WOLFSSL_STACK* wolfSSL_CertManagerGetCerts(WOLFSSL_CERT_MANAGER* cm)
382383
/* Get pointer to DER encoding of certificate. */
383384
derBuffer = certBuffers[i]->buffer;
384385
/* Decode certificate. */
385-
wolfSSL_d2i_X509(&x509, &derBuffer, certBuffers[i]->length);
386+
wolfSSL_d2i_X509(&x509, &derBuffer, (int)certBuffers[i]->length);
386387
if (x509 == NULL) {
387388
err = 1;
388389
}
@@ -816,13 +817,13 @@ int wolfSSL_CertManagerVerify(WOLFSSL_CERT_MANAGER* cm, const char* fname,
816817
#endif
817818
{
818819
WOLFSSL_MSG("Getting dynamic buffer");
819-
buff = (byte*)XMALLOC(sz, cm->heap, DYNAMIC_TYPE_FILE);
820+
buff = (byte*)XMALLOC((size_t)sz, cm->heap, DYNAMIC_TYPE_FILE);
820821
if (buff == NULL) {
821822
ret = WOLFSSL_BAD_FILE;
822823
}
823824
}
824825
/* Read all the file into buffer. */
825-
if ((ret == WOLFSSL_SUCCESS) && ((size_t)XFREAD(buff, 1, sz, file) !=
826+
if ((ret == WOLFSSL_SUCCESS) && (XFREAD(buff, 1, (size_t)sz, file) !=
826827
(size_t)sz)) {
827828
ret = WOLFSSL_BAD_FILE;
828829
}
@@ -942,7 +943,7 @@ static WC_INLINE int cm_get_signer_memory(Signer* signer)
942943
#endif
943944

944945
/* Add dynamic bytes needed. */
945-
sz += signer->pubKeySize;
946+
sz += (int)signer->pubKeySize;
946947
sz += signer->nameLen;
947948

948949
return sz;
@@ -1103,7 +1104,7 @@ static WC_INLINE int cm_restore_cert_row(WOLFSSL_CERT_MANAGER* cm,
11031104
/* Copy in public key. */
11041105
XMEMCPY(publicKey, current + idx, signer->pubKeySize);
11051106
signer->publicKey = publicKey;
1106-
idx += signer->pubKeySize;
1107+
idx += (int)signer->pubKeySize;
11071108

11081109
/* Copy in certificate name length. */
11091110
XMEMCPY(&signer->nameLen, current + idx, sizeof(signer->nameLen));
@@ -1117,7 +1118,7 @@ static WC_INLINE int cm_restore_cert_row(WOLFSSL_CERT_MANAGER* cm,
11171118
}
11181119
if (ret == 0) {
11191120
/* Allocate memory for public key to be stored in. */
1120-
signer->name = (char*)XMALLOC(signer->nameLen, cm->heap,
1121+
signer->name = (char*)XMALLOC((size_t)signer->nameLen, cm->heap,
11211122
DYNAMIC_TYPE_SUBJECT_CN);
11221123
if (signer->name == NULL) {
11231124
ret = MEMORY_E;
@@ -1126,7 +1127,7 @@ static WC_INLINE int cm_restore_cert_row(WOLFSSL_CERT_MANAGER* cm,
11261127

11271128
if (ret == 0) {
11281129
/* Copy in certificate name. */
1129-
XMEMCPY(signer->name, current + idx, signer->nameLen);
1130+
XMEMCPY(signer->name, current + idx, (size_t)signer->nameLen);
11301131
idx += signer->nameLen;
11311132

11321133
/* Copy in hash of subject name. */
@@ -1190,15 +1191,15 @@ static WC_INLINE int cm_store_cert_row(WOLFSSL_CERT_MANAGER* cm, byte* current,
11901191
added += (int)sizeof(list->keyOID);
11911192

11921193
/* Public key. */
1193-
XMEMCPY(current + added, list->publicKey, list->pubKeySize);
1194-
added += list->pubKeySize;
1194+
XMEMCPY(current + added, list->publicKey, (size_t)list->pubKeySize);
1195+
added += (int)list->pubKeySize;
11951196

11961197
/* Certificate name length. */
11971198
XMEMCPY(current + added, &list->nameLen, sizeof(list->nameLen));
11981199
added += (int)sizeof(list->nameLen);
11991200

12001201
/* Certificate name. */
1201-
XMEMCPY(current + added, list->name, list->nameLen);
1202+
XMEMCPY(current + added, list->name, (size_t)list->nameLen);
12021203
added += list->nameLen;
12031204

12041205
/* Hash of subject name. */
@@ -1287,8 +1288,6 @@ int CM_SaveCertCache(WOLFSSL_CERT_MANAGER* cm, const char* fname)
12871288
{
12881289
XFILE file;
12891290
int ret = WOLFSSL_SUCCESS;
1290-
int memSz;
1291-
byte* mem;
12921291

12931292
WOLFSSL_ENTER("CM_SaveCertCache");
12941293

@@ -1306,17 +1305,18 @@ int CM_SaveCertCache(WOLFSSL_CERT_MANAGER* cm, const char* fname)
13061305
}
13071306

13081307
if (ret == WOLFSSL_SUCCESS) {
1308+
byte* mem;
13091309
/* Calculate size of memory required to store CA table. */
1310-
memSz = cm_get_cert_cache_mem_size(cm);
1310+
size_t memSz = (size_t)cm_get_cert_cache_mem_size(cm);
13111311
/* Allocate memory to hold CA table. */
1312-
mem = (byte*)XMALLOC(memSz, cm->heap, DYNAMIC_TYPE_TMP_BUFFER);
1312+
mem = (byte*)XMALLOC(memSz, cm->heap, DYNAMIC_TYPE_TMP_BUFFER);
13131313
if (mem == NULL) {
13141314
WOLFSSL_MSG("Alloc for tmp buffer failed");
13151315
ret = MEMORY_E;
13161316
}
13171317
if (ret == WOLFSSL_SUCCESS) {
13181318
/* Store CA table in memory. */
1319-
ret = cm_do_mem_save_cert_cache(cm, mem, memSz);
1319+
ret = cm_do_mem_save_cert_cache(cm, mem, (int)memSz);
13201320
}
13211321
if (ret == WOLFSSL_SUCCESS) {
13221322
/* Write memory to file. */
@@ -1753,7 +1753,7 @@ int wolfSSL_CertManagerCheckCRL(WOLFSSL_CERT_MANAGER* cm,
17531753
#endif
17541754
{
17551755
/* Initialize decoded certificate with buffer. */
1756-
InitDecodedCert(cert, der, sz, NULL);
1756+
InitDecodedCert(cert, der, (word32)sz, NULL);
17571757

17581758
/* Parse certificate and perform CRL checks. */
17591759
ret = ParseCertRelative(cert, CERT_TYPE, VERIFY_CRL, cm);
@@ -2224,7 +2224,7 @@ int wolfSSL_CertManagerCheckOCSP(WOLFSSL_CERT_MANAGER* cm,
22242224
#endif
22252225
{
22262226
/* Initialize decoded certificate with buffer. */
2227-
InitDecodedCert(cert, der, sz, NULL);
2227+
InitDecodedCert(cert, der, (word32)sz, NULL);
22282228

22292229
/* Parse certificate and perform CRL checks. */
22302230
ret = ParseCertRelative(cert, CERT_TYPE, VERIFY_OCSP, cm);
@@ -2307,14 +2307,14 @@ int wolfSSL_CertManagerSetOCSPOverrideURL(WOLFSSL_CERT_MANAGER* cm,
23072307
/* Calculate size of URL string. Include terminator character. */
23082308
int urlSz = (int)XSTRLEN(url) + 1;
23092309
/* Allocate memory for URL to be copied into. */
2310-
cm->ocspOverrideURL = (char*)XMALLOC(urlSz, cm->heap,
2310+
cm->ocspOverrideURL = (char*)XMALLOC((size_t)urlSz, cm->heap,
23112311
DYNAMIC_TYPE_URL);
23122312
if (cm->ocspOverrideURL == NULL) {
23132313
ret = MEMORY_E;
23142314
}
23152315
if (ret == WOLFSSL_SUCCESS) {
23162316
/* Copy URL into certificate manager. */
2317-
XMEMCPY(cm->ocspOverrideURL, url, urlSz);
2317+
XMEMCPY(cm->ocspOverrideURL, url, (size_t)urlSz);
23182318
}
23192319
}
23202320
else {

0 commit comments

Comments
 (0)