Hi,
On Tue, Apr 28, 2026 at 01:07:15PM +0000, Stefan Berger wrote:
> Set the sizes of byte arrays holding TPM requests and responses to avoid a
> terminating NUL byte to be added and to only compare the expected part of
> responses.
>
> Signed-off-by: Stefan Berger <[email protected]>
> ---
> tests/qtest/tpm-tests.c | 4 ++--
> tests/qtest/tpm-util.c | 10 +++++-----
> 2 files changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/tests/qtest/tpm-tests.c b/tests/qtest/tpm-tests.c
> index 197714f8d9..dcbf5457ed 100644
> --- a/tests/qtest/tpm-tests.c
> +++ b/tests/qtest/tpm-tests.c
> @@ -59,7 +59,7 @@ void tpm_test_swtpm_test(const char *src_tpm_path, tx_func
> *tx,
> tpm_util_startup(s, tx);
> tpm_util_pcrextend(s, tx);
>
> - static const unsigned char tpm_pcrread_resp[] =
> + static const unsigned char tpm_pcrread_resp[62] =
> "\x80\x01\x00\x00\x00\x3e\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00"
> "\x00\x01\x00\x0b\x03\x00\x04\x00\x00\x00\x00\x01\x00\x20\xf6\x85"
> "\x98\xe5\x86\x8d\xe6\x8b\x97\x29\x99\x60\xf2\x71\x7d\x17\x67\x89"
Can we define it as an initializer list instead of a string literal like
below?
static const unsigned char tpm_pcrread_resp[] = {0x80, 0x01, 0x00,
0x00,...};
This one avoids the null terminator.
static const unsigned char tpm_pcrread_resp[] =
{0x80,0x01,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x16,0x00,0x00,0x00,0x01,0x00,0x0b,0x03,0x00,0x04,0x00,
0x00,0x00,0x00,0x01,0x00,0x20,0xf6,0x85,0x98,0xe5,0x86,0x8d,
0xe6,0x8b,0x97,0x29,0x99,0x60,0xf2,0x71,0x7d,0x17,0x67,0x89,
0xa4,0x2f,0x9a,0xae,0xa8,0xc7,0xb7,0xaa,0x79,0xa8,0x62,0x56,
0xc1,0xde};
static const unsigned char tpm_pcrextend[] =
{0x80,0x02,0x00,0x00,0x00,0x41,0x00,0x00,0x01,0x82,0x00,0x00,
0x00,0x0a,0x00,0x00,0x00,0x09,0x40,0x00,0x00,0x09,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x0b,0x74,0x65,0x73,
0x74,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00};
static const unsigned char tpm_pcrextend_resp[] =
{0x80,0x02,0x00,0x00,0x00,0x13,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0x00,0x00};
static const unsigned char tpm_pcrread[] =
{0x80,0x01,0x00,0x00,0x00,0x14,0x00,0x00,0x01,0x7e,0x00,0x00,
0x00,0x01,0x00,0x0b,0x03,0x00,0x04,0x00};
> @@ -105,7 +105,7 @@ void tpm_test_swtpm_migration_test(const char
> *src_tpm_path,
> tpm_util_startup(src_qemu, tx);
> tpm_util_pcrextend(src_qemu, tx);
>
> - static const unsigned char tpm_pcrread_resp[] =
> + static const unsigned char tpm_pcrread_resp[62] =
> "\x80\x01\x00\x00\x00\x3e\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00"
> "\x00\x01\x00\x0b\x03\x00\x04\x00\x00\x00\x00\x01\x00\x20\xf6\x85"
> "\x98\xe5\x86\x8d\xe6\x8b\x97\x29\x99\x60\xf2\x71\x7d\x17\x67\x89"
> diff --git a/tests/qtest/tpm-util.c b/tests/qtest/tpm-util.c
> index 2cb2dd4796..1a47099807 100644
> --- a/tests/qtest/tpm-util.c
> +++ b/tests/qtest/tpm-util.c
> @@ -54,9 +54,9 @@ void tpm_util_crb_transfer(QTestState *s,
> void tpm_util_startup(QTestState *s, tx_func *tx)
> {
> unsigned char buffer[1024];
> - static const unsigned char tpm_startup[] =
> + static const unsigned char tpm_startup[12] =
> "\x80\x01\x00\x00\x00\x0c\x00\x00\x01\x44\x00\x00";
> - static const unsigned char tpm_startup_resp[] =
> + static const unsigned char tpm_startup_resp[10] =
> "\x80\x01\x00\x00\x00\x0a\x00\x00\x00\x00";
>
> tx(s, tpm_startup, sizeof(tpm_startup), buffer, sizeof(buffer));
> @@ -68,14 +68,14 @@ void tpm_util_startup(QTestState *s, tx_func *tx)
> void tpm_util_pcrextend(QTestState *s, tx_func *tx)
> {
> unsigned char buffer[1024];
> - static const unsigned char tpm_pcrextend[] =
> + static const unsigned char tpm_pcrextend[65] =
> "\x80\x02\x00\x00\x00\x41\x00\x00\x01\x82\x00\x00\x00\x0a\x00\x00"
> "\x00\x09\x40\x00\x00\x09\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00"
> "\x0b\x74\x65\x73\x74\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
> "\x00";
>
> - static const unsigned char tpm_pcrextend_resp[] =
> + static const unsigned char tpm_pcrextend_resp[19] =
> "\x80\x02\x00\x00\x00\x13\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
> "\x01\x00\x00";
>
> @@ -89,7 +89,7 @@ void tpm_util_pcrread(QTestState *s, tx_func *tx,
> const unsigned char *exp_resp, size_t exp_resp_size)
> {
> unsigned char buffer[1024];
> - static const unsigned char tpm_pcrread[] =
> + static const unsigned char tpm_pcrread[20] =
> "\x80\x01\x00\x00\x00\x14\x00\x00\x01\x7e\x00\x00\x00\x01\x00\x0b"
> "\x03\x00\x04\x00";
>
> --
> 2.43.0
>
Regards,
Arun Menon