F-6839 - Cover truncated-buffer error path in DecodeX509Cert test

pull/551/head
aidan garske 2026-07-13 13:03:10 -07:00
parent 14d02a32b2
commit 5c682e167b
1 changed files with 6 additions and 0 deletions

View File

@ -4441,6 +4441,7 @@ static void test_TPM2_ASN_DecodeX509Cert_Errors(void)
int rc;
DecodedX509 x509;
byte garbage[16];
byte trunc[4];
XMEMSET(&x509, 0, sizeof(x509));
XMEMSET(garbage, 0xFF, sizeof(garbage));
@ -4455,6 +4456,11 @@ static void test_TPM2_ASN_DecodeX509Cert_Errors(void)
rc = TPM2_ASN_DecodeX509Cert(garbage, (int)sizeof(garbage), &x509);
AssertIntNE(rc, 0);
/* outer SEQUENCE whose length runs past the buffer (TPM_RC_INSUFFICIENT) */
trunc[0] = 0x30; trunc[1] = 0x20; trunc[2] = 0x00; trunc[3] = 0x00;
rc = TPM2_ASN_DecodeX509Cert(trunc, (int)sizeof(trunc), &x509);
AssertIntNE(rc, 0);
printf("Test TPM Wrapper: %-40s Passed\n", "ASN DecodeX509Cert errors:");
#endif
}