From 5c682e167b1ab91986709c9bfbd0a0f6b70c19e5 Mon Sep 17 00:00:00 2001 From: aidan garske Date: Mon, 13 Jul 2026 13:03:10 -0700 Subject: [PATCH] F-6839 - Cover truncated-buffer error path in DecodeX509Cert test --- tests/unit_tests.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/unit_tests.c b/tests/unit_tests.c index 45954737..e31682a0 100644 --- a/tests/unit_tests.c +++ b/tests/unit_tests.c @@ -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 }