Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion wolfcrypt/src/pkcs12.c
Original file line number Diff line number Diff line change
Expand Up @@ -1546,8 +1546,13 @@ int wc_PKCS12_parse_ex(WC_PKCS12* pkcs12, const char* psw,
*pkeySz = (word32)size;
}
else {
*pkeySz = (word32)ToTraditional_ex(*pkey,
ret = ToTraditional_ex(*pkey,
(word32)size, &algId);
if (ret < 0) {
goto exit_pk12par;
} else {
*pkeySz = (word32)ret;
}
Comment on lines +1551 to +1555
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change introduces a new failure path when a KeyBag contains an invalid/unsupported PKCS#8 wrapper (ToTraditional_ex returns < 0). There are PKCS#12 parser tests in tests/api/test_pkcs12.c, but none appear to exercise this specific regression; adding a crafted PKCS#12 (or mutating an existing one) that forces ToTraditional_ex() to fail would help prevent reintroducing the original issue (negative return value being treated as a size).

Suggested change
if (ret < 0) {
goto exit_pk12par;
} else {
*pkeySz = (word32)ret;
}
if ((ret <= 0) || (ret > size)) {
if (ret >= 0) {
ret = ASN_PARSE_E;
}
XFREE(*pkey, pkcs12->heap,
DYNAMIC_TYPE_PUBLIC_KEY);
*pkey = NULL;
*pkeySz = 0;
goto exit_pk12par;
}
*pkeySz = (word32)ret;

Copilot uses AI. Check for mistakes.
}
}

Expand Down
Loading