Skip to content

Commit 13cadbb

Browse files
authored
Merge pull request #6903 from douzzer/20231021-fix-null-derefs
20231021-fix-null-derefs
2 parents 1de0488 + 501299b commit 13cadbb

2 files changed

Lines changed: 16 additions & 15 deletions

File tree

examples/pem/pem.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ static int pemApp_ReadFile(FILE* fp, unsigned char** pdata, word32* plen)
151151
* @return 0 on success.
152152
* @return 1 on failure.
153153
*/
154-
static int WriteFile(FILE* fp, unsigned char* data, word32 len)
154+
static int WriteFile(FILE* fp, const char* data, word32 len)
155155
{
156156
int ret = 0;
157157

@@ -995,7 +995,7 @@ int main(int argc, char* argv[])
995995
}
996996
if (ret == 0) {
997997
/* Write out PEM. */
998-
ret = WriteFile(out_file, out, out_len);
998+
ret = WriteFile(out_file, out ? (const char *)out : "", out_len);
999999
if (ret != 0) {
10001000
fprintf(stderr, "Could not write file\n");
10011001
}

tests/api.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26690,32 +26690,32 @@ static int LoadPKCS7SignedDataCerts(
2669026690
ExpectIntGT(*intCARootSz, 0);
2669126691

2669226692
ExpectTrue((fp = XFOPEN(intCA1RSA, "rb")) != XBADFILE);
26693-
*intCA1Sz = (word32)XFREAD(intCA1, 1, *intCA1Sz, fp);
2669426693
if (fp != XBADFILE) {
26694+
*intCA1Sz = (word32)XFREAD(intCA1, 1, *intCA1Sz, fp);
2669526695
XFCLOSE(fp);
2669626696
fp = XBADFILE;
2669726697
}
2669826698
ExpectIntGT(*intCA1Sz, 0);
2669926699

2670026700
ExpectTrue((fp = XFOPEN(intCA2RSA, "rb")) != XBADFILE);
26701-
*intCA2Sz = (word32)XFREAD(intCA2, 1, *intCA2Sz, fp);
2670226701
if (fp != XBADFILE) {
26702+
*intCA2Sz = (word32)XFREAD(intCA2, 1, *intCA2Sz, fp);
2670326703
XFCLOSE(fp);
2670426704
fp = XBADFILE;
2670526705
}
2670626706
ExpectIntGT(*intCA2Sz, 0);
2670726707

2670826708
ExpectTrue((fp = XFOPEN(intServCertRSA, "rb")) != XBADFILE);
26709-
*certSz = (word32)XFREAD(cert, 1, *certSz, fp);
2671026709
if (fp != XBADFILE) {
26710+
*certSz = (word32)XFREAD(cert, 1, *certSz, fp);
2671126711
XFCLOSE(fp);
2671226712
fp = XBADFILE;
2671326713
}
2671426714
ExpectIntGT(*certSz, 0);
2671526715

2671626716
ExpectTrue((fp = XFOPEN(intServKeyRSA, "rb")) != XBADFILE);
26717-
*keySz = (word32)XFREAD(key, 1, *keySz, fp);
2671826717
if (fp != XBADFILE) {
26718+
*keySz = (word32)XFREAD(key, 1, *keySz, fp);
2671926719
XFCLOSE(fp);
2672026720
fp = XBADFILE;
2672126721
}
@@ -26734,16 +26734,16 @@ static int LoadPKCS7SignedDataCerts(
2673426734
XMEMCPY(cert, client_cert_der_1024, *certSz);
2673526735
#else
2673626736
ExpectTrue((fp = XFOPEN(cli1024Key, "rb")) != XBADFILE);
26737-
*keySz = (word32)XFREAD(key, 1, *keySz, fp);
2673826737
if (fp != XBADFILE) {
26738+
*keySz = (word32)XFREAD(key, 1, *keySz, fp);
2673926739
XFCLOSE(fp);
2674026740
fp = XBADFILE;
2674126741
}
2674226742
ExpectIntGT(*keySz, 0);
2674326743

2674426744
ExpectTrue((fp = XFOPEN(cli1024Cert, "rb")) != XBADFILE);
26745-
*certSz = (word32)XFREAD(cert, 1, *certSz, fp);
2674626745
if (fp != XBADFILE) {
26746+
*certSz = (word32)XFREAD(cert, 1, *certSz, fp);
2674726747
XFCLOSE(fp);
2674826748
fp = XBADFILE;
2674926749
}
@@ -26756,40 +26756,41 @@ static int LoadPKCS7SignedDataCerts(
2675626756
case ECC_TYPE:
2675726757
if (useIntermediateCertChain == 1) {
2675826758
ExpectTrue((fp = XFOPEN(intCARootECC, "rb")) != XBADFILE);
26759-
*intCARootSz = (word32)XFREAD(intCARoot, 1, *intCARootSz, fp);
2676026759
if (fp != XBADFILE) {
26760+
*intCARootSz = (word32)XFREAD(intCARoot, 1, *intCARootSz,
26761+
fp);
2676126762
XFCLOSE(fp);
2676226763
fp = XBADFILE;
2676326764
}
2676426765
ExpectIntGT(*intCARootSz, 0);
2676526766

2676626767
ExpectTrue((fp = XFOPEN(intCA1ECC, "rb")) != XBADFILE);
26767-
*intCA1Sz = (word32)XFREAD(intCA1, 1, *intCA1Sz, fp);
2676826768
if (fp != XBADFILE) {
26769+
*intCA1Sz = (word32)XFREAD(intCA1, 1, *intCA1Sz, fp);
2676926770
XFCLOSE(fp);
2677026771
fp = XBADFILE;
2677126772
}
2677226773
ExpectIntGT(*intCA1Sz, 0);
2677326774

2677426775
ExpectTrue((fp = XFOPEN(intCA2ECC, "rb")) != XBADFILE);
26775-
*intCA2Sz = (word32)XFREAD(intCA2, 1, *intCA2Sz, fp);
2677626776
if (fp != XBADFILE) {
26777+
*intCA2Sz = (word32)XFREAD(intCA2, 1, *intCA2Sz, fp);
2677726778
XFCLOSE(fp);
2677826779
fp = XBADFILE;
2677926780
}
2678026781
ExpectIntGT(*intCA2Sz, 0);
2678126782

2678226783
ExpectTrue((fp = XFOPEN(intServCertECC, "rb")) != XBADFILE);
26783-
*certSz = (word32)XFREAD(cert, 1, *certSz, fp);
2678426784
if (fp != XBADFILE) {
26785+
*certSz = (word32)XFREAD(cert, 1, *certSz, fp);
2678526786
XFCLOSE(fp);
2678626787
fp = XBADFILE;
2678726788
}
2678826789
ExpectIntGT(*certSz, 0);
2678926790

2679026791
ExpectTrue((fp = XFOPEN(intServKeyECC, "rb")) != XBADFILE);
26791-
*keySz = (word32)XFREAD(key, 1, *keySz, fp);
2679226792
if (fp != XBADFILE) {
26793+
*keySz = (word32)XFREAD(key, 1, *keySz, fp);
2679326794
XFCLOSE(fp);
2679426795
fp = XBADFILE;
2679526796
}
@@ -26803,16 +26804,16 @@ static int LoadPKCS7SignedDataCerts(
2680326804
XMEMCPY(cert, cliecc_cert_der_256, *certSz);
2680426805
#else
2680526806
ExpectTrue((fp = XFOPEN(cliEccKey, "rb")) != XBADFILE);
26806-
*keySz = (word32)XFREAD(key, 1, *keySz, fp);
2680726807
if (fp != XBADFILE) {
26808+
*keySz = (word32)XFREAD(key, 1, *keySz, fp);
2680826809
XFCLOSE(fp);
2680926810
fp = XBADFILE;
2681026811
}
2681126812
ExpectIntGT(*keySz, 0);
2681226813

2681326814
ExpectTrue((fp = XFOPEN(cliEccCert, "rb")) != XBADFILE);
26814-
*certSz = (word32)XFREAD(cert, 1, *certSz, fp);
2681526815
if (fp != XBADFILE) {
26816+
*certSz = (word32)XFREAD(cert, 1, *certSz, fp);
2681626817
XFCLOSE(fp);
2681726818
fp = XBADFILE;
2681826819
}

0 commit comments

Comments
 (0)