Skip to content

Commit

Permalink
Merge pull request wolfSSL#6903 from douzzer/20231021-fix-null-derefs
Browse files Browse the repository at this point in the history
20231021-fix-null-derefs
  • Loading branch information
SparkiDev authored Oct 24, 2023
2 parents 1de0488 + 501299b commit 13cadbb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions examples/pem/pem.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ static int pemApp_ReadFile(FILE* fp, unsigned char** pdata, word32* plen)
* @return 0 on success.
* @return 1 on failure.
*/
static int WriteFile(FILE* fp, unsigned char* data, word32 len)
static int WriteFile(FILE* fp, const char* data, word32 len)
{
int ret = 0;

Expand Down Expand Up @@ -995,7 +995,7 @@ int main(int argc, char* argv[])
}
if (ret == 0) {
/* Write out PEM. */
ret = WriteFile(out_file, out, out_len);
ret = WriteFile(out_file, out ? (const char *)out : "", out_len);
if (ret != 0) {
fprintf(stderr, "Could not write file\n");
}
Expand Down
27 changes: 14 additions & 13 deletions tests/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -26690,32 +26690,32 @@ static int LoadPKCS7SignedDataCerts(
ExpectIntGT(*intCARootSz, 0);

ExpectTrue((fp = XFOPEN(intCA1RSA, "rb")) != XBADFILE);
*intCA1Sz = (word32)XFREAD(intCA1, 1, *intCA1Sz, fp);
if (fp != XBADFILE) {
*intCA1Sz = (word32)XFREAD(intCA1, 1, *intCA1Sz, fp);
XFCLOSE(fp);
fp = XBADFILE;
}
ExpectIntGT(*intCA1Sz, 0);

ExpectTrue((fp = XFOPEN(intCA2RSA, "rb")) != XBADFILE);
*intCA2Sz = (word32)XFREAD(intCA2, 1, *intCA2Sz, fp);
if (fp != XBADFILE) {
*intCA2Sz = (word32)XFREAD(intCA2, 1, *intCA2Sz, fp);
XFCLOSE(fp);
fp = XBADFILE;
}
ExpectIntGT(*intCA2Sz, 0);

ExpectTrue((fp = XFOPEN(intServCertRSA, "rb")) != XBADFILE);
*certSz = (word32)XFREAD(cert, 1, *certSz, fp);
if (fp != XBADFILE) {
*certSz = (word32)XFREAD(cert, 1, *certSz, fp);
XFCLOSE(fp);
fp = XBADFILE;
}
ExpectIntGT(*certSz, 0);

ExpectTrue((fp = XFOPEN(intServKeyRSA, "rb")) != XBADFILE);
*keySz = (word32)XFREAD(key, 1, *keySz, fp);
if (fp != XBADFILE) {
*keySz = (word32)XFREAD(key, 1, *keySz, fp);
XFCLOSE(fp);
fp = XBADFILE;
}
Expand All @@ -26734,16 +26734,16 @@ static int LoadPKCS7SignedDataCerts(
XMEMCPY(cert, client_cert_der_1024, *certSz);
#else
ExpectTrue((fp = XFOPEN(cli1024Key, "rb")) != XBADFILE);
*keySz = (word32)XFREAD(key, 1, *keySz, fp);
if (fp != XBADFILE) {
*keySz = (word32)XFREAD(key, 1, *keySz, fp);
XFCLOSE(fp);
fp = XBADFILE;
}
ExpectIntGT(*keySz, 0);

ExpectTrue((fp = XFOPEN(cli1024Cert, "rb")) != XBADFILE);
*certSz = (word32)XFREAD(cert, 1, *certSz, fp);
if (fp != XBADFILE) {
*certSz = (word32)XFREAD(cert, 1, *certSz, fp);
XFCLOSE(fp);
fp = XBADFILE;
}
Expand All @@ -26756,40 +26756,41 @@ static int LoadPKCS7SignedDataCerts(
case ECC_TYPE:
if (useIntermediateCertChain == 1) {
ExpectTrue((fp = XFOPEN(intCARootECC, "rb")) != XBADFILE);
*intCARootSz = (word32)XFREAD(intCARoot, 1, *intCARootSz, fp);
if (fp != XBADFILE) {
*intCARootSz = (word32)XFREAD(intCARoot, 1, *intCARootSz,
fp);
XFCLOSE(fp);
fp = XBADFILE;
}
ExpectIntGT(*intCARootSz, 0);

ExpectTrue((fp = XFOPEN(intCA1ECC, "rb")) != XBADFILE);
*intCA1Sz = (word32)XFREAD(intCA1, 1, *intCA1Sz, fp);
if (fp != XBADFILE) {
*intCA1Sz = (word32)XFREAD(intCA1, 1, *intCA1Sz, fp);
XFCLOSE(fp);
fp = XBADFILE;
}
ExpectIntGT(*intCA1Sz, 0);

ExpectTrue((fp = XFOPEN(intCA2ECC, "rb")) != XBADFILE);
*intCA2Sz = (word32)XFREAD(intCA2, 1, *intCA2Sz, fp);
if (fp != XBADFILE) {
*intCA2Sz = (word32)XFREAD(intCA2, 1, *intCA2Sz, fp);
XFCLOSE(fp);
fp = XBADFILE;
}
ExpectIntGT(*intCA2Sz, 0);

ExpectTrue((fp = XFOPEN(intServCertECC, "rb")) != XBADFILE);
*certSz = (word32)XFREAD(cert, 1, *certSz, fp);
if (fp != XBADFILE) {
*certSz = (word32)XFREAD(cert, 1, *certSz, fp);
XFCLOSE(fp);
fp = XBADFILE;
}
ExpectIntGT(*certSz, 0);

ExpectTrue((fp = XFOPEN(intServKeyECC, "rb")) != XBADFILE);
*keySz = (word32)XFREAD(key, 1, *keySz, fp);
if (fp != XBADFILE) {
*keySz = (word32)XFREAD(key, 1, *keySz, fp);
XFCLOSE(fp);
fp = XBADFILE;
}
Expand All @@ -26803,16 +26804,16 @@ static int LoadPKCS7SignedDataCerts(
XMEMCPY(cert, cliecc_cert_der_256, *certSz);
#else
ExpectTrue((fp = XFOPEN(cliEccKey, "rb")) != XBADFILE);
*keySz = (word32)XFREAD(key, 1, *keySz, fp);
if (fp != XBADFILE) {
*keySz = (word32)XFREAD(key, 1, *keySz, fp);
XFCLOSE(fp);
fp = XBADFILE;
}
ExpectIntGT(*keySz, 0);

ExpectTrue((fp = XFOPEN(cliEccCert, "rb")) != XBADFILE);
*certSz = (word32)XFREAD(cert, 1, *certSz, fp);
if (fp != XBADFILE) {
*certSz = (word32)XFREAD(cert, 1, *certSz, fp);
XFCLOSE(fp);
fp = XBADFILE;
}
Expand Down

0 comments on commit 13cadbb

Please sign in to comment.