Skip to content

Commit 6ef580c

Browse files
committed
fix PKCS#7 build when using NO_PKCS7_STREAM
1 parent a595f10 commit 6ef580c

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

tests/api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28961,7 +28961,7 @@ static int test_wc_PKCS7_EncodeSignedData_ex(void)
2896128961
outputHead, outputHeadSz, outputFoot, 0), WC_PKCS7_WANT_READ_E);
2896228962
#else
2896328963
AssertIntEQ(wc_PKCS7_VerifySignedData_ex(pkcs7, hashBuf, hashSz,
28964-
outputHead, outputHeadSz, outputFoot, 0), ASN_PARSE_E);
28964+
outputHead, outputHeadSz, outputFoot, 0), BUFFER_E);
2896528965
#endif
2896628966

2896728967
wc_PKCS7_Free(pkcs7);

wolfcrypt/src/pkcs7.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4790,6 +4790,9 @@ static int PKCS7_VerifySignedData(PKCS7* pkcs7, const byte* hashBuf,
47904790

47914791
pkiMsg2 = pkiMsg;
47924792
pkiMsg2Sz = pkiMsgSz;
4793+
4794+
/* reset ret */
4795+
ret = 0;
47934796
}
47944797

47954798
#ifndef NO_PKCS7_STREAM
@@ -4963,14 +4966,14 @@ static int PKCS7_VerifySignedData(PKCS7* pkcs7, const byte* hashBuf,
49634966
ret = 0; /* reset ret state on degenerate case */
49644967
}
49654968

4966-
#ifndef NO_PKCS7_STREAM
49674969
/* save content */
49684970
if (detached == 1) {
49694971
/* if detached, use content from user in pkcs7 struct */
49704972
content = pkcs7->content;
49714973
contentSz = pkcs7->contentSz;
49724974
}
49734975

4976+
#ifndef NO_PKCS7_STREAM
49744977
if (content != NULL) {
49754978
XFREE(pkcs7->stream->content, pkcs7->heap, DYNAMIC_TYPE_PKCS7);
49764979
pkcs7->stream->content = (byte*)XMALLOC(contentSz, pkcs7->heap,
@@ -4986,6 +4989,7 @@ static int PKCS7_VerifySignedData(PKCS7* pkcs7, const byte* hashBuf,
49864989
}
49874990
#endif /* !NO_PKCS7_STREAM */
49884991

4992+
/* Certificates begin "footer" section (ie pkiMsg2) if being used */
49894993
/* Get the implicit[0] set of certificates */
49904994
if (ret == 0 && idx >= pkiMsg2Sz)
49914995
ret = BUFFER_E;
@@ -5270,6 +5274,9 @@ static int PKCS7_VerifySignedData(PKCS7* pkcs7, const byte* hashBuf,
52705274
break;
52715275
}
52725276
stateIdx = idx;
5277+
#else
5278+
/* if not streaming, maxIdx is just pkiMsg2Sz */
5279+
maxIdx = pkiMsg2Sz;
52735280
#endif
52745281

52755282
/* set contentType and size after init of PKCS7 structure */
@@ -11619,7 +11626,7 @@ WOLFSSL_API int wc_PKCS7_DecodeAuthEnvelopedData(PKCS7* pkcs7, byte* in,
1161911626
{
1162011627
#if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
1162111628
int recipFound = 0;
11622-
int ret = 0, length;
11629+
int ret = 0, length = 0;
1162311630
word32 idx = 0;
1162411631
#ifndef NO_PKCS7_STREAM
1162511632
word32 tmpIdx = 0;
@@ -12019,8 +12026,6 @@ WOLFSSL_API int wc_PKCS7_DecodeAuthEnvelopedData(PKCS7* pkcs7, byte* in,
1201912026

1202012027
length = pkcs7->stream->expected;
1202112028
encodedAttribs = pkcs7->stream->aad;
12022-
#else
12023-
length = 0;
1202412029
#endif
1202512030

1202612031
/* save pointer and length */
@@ -12541,7 +12546,7 @@ int wc_PKCS7_DecodeEncryptedData(PKCS7* pkcs7, byte* in, word32 inSz,
1254112546
#ifndef NO_PKCS7_STREAM
1254212547
word32 tmpIdx = 0;
1254312548
#endif
12544-
word32 contentType = 0, encOID;
12549+
word32 contentType = 0, encOID = 0;
1254512550

1254612551
int expBlockSz = 0;
1254712552
byte tmpIvBuf[MAX_CONTENT_IV_SIZE];
@@ -12797,8 +12802,6 @@ int wc_PKCS7_DecodeEncryptedData(PKCS7* pkcs7, byte* in, word32 inSz,
1279712802
encryptedContentSz = pkcs7->stream->varThree;
1279812803
version = pkcs7->stream->vers;
1279912804
tmpIv = pkcs7->stream->tmpIv;
12800-
#else
12801-
encOID = 0;
1280212805
#endif
1280312806
if (ret == 0 && (encryptedContent = (byte*)XMALLOC(
1280412807
encryptedContentSz, pkcs7->heap, DYNAMIC_TYPE_PKCS7)) == NULL) {

0 commit comments

Comments
 (0)