Skip to content

Commit b4d2cd6

Browse files
committed
Fix feedback from review
1 parent e0a19a7 commit b4d2cd6

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

tests/api/test_pkcs12.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,9 @@ int test_wc_d2i_PKCS12_oid_underflow(void)
245245
WC_PKCS12* pkcs12 = NULL;
246246

247247
/* Crafted PKCS12 DER: the inner ContentInfo SEQUENCE declares length 5,
248-
* but contains a valid 11-byte OID (1.2.840.113549.1.7.1). Without the
249-
* bounds check, (word32)curSz - (localIdx - curIdx) = 5 - 11 underflows
248+
* but contains a valid OID (1.2.840.113549.1.7.1) that is 11 bytes
249+
* on the wire (tag 06 + length 09 + 9 value bytes). Without the bounds
250+
* check, (word32)curSz - (localIdx - curIdx) = 5 - 11 underflows
250251
* to ~4GB. */
251252
static const byte crafted[] = {
252253
0x30, 0x23, /* outer SEQ */
@@ -263,7 +264,8 @@ int test_wc_d2i_PKCS12_oid_underflow(void)
263264
};
264265

265266
ExpectNotNull(pkcs12 = wc_PKCS12_new());
266-
ExpectIntLT(wc_d2i_PKCS12(crafted, (word32)sizeof(crafted), pkcs12), 0);
267+
ExpectIntEQ(wc_d2i_PKCS12(crafted, (word32)sizeof(crafted), pkcs12),
268+
ASN_PARSE_E);
267269
wc_PKCS12_free(pkcs12);
268270
#endif
269271
return EXPECT_RESULT();

wolfcrypt/src/pkcs12.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ static int GetSafeContent(WC_PKCS12* pkcs12, const byte* input,
335335
}
336336

337337
/* Check that OID did not consume more than the sequence length */
338-
if ((localIdx - curIdx) > (word32)curSz) {
338+
if (localIdx > curIdx + (word32)curSz) {
339339
freeSafe(safe, pkcs12->heap);
340340
return ASN_PARSE_E;
341341
}

0 commit comments

Comments
 (0)