diff options
author | Juergen Repp <Juergen.Repp@sit.fraunhofer.de> | 2018-12-13 13:16:17 +0100 |
---|---|---|
committer | Tadeusz Struk <tadeusz.struk@intel.com> | 2018-12-13 18:55:14 -0800 |
commit | 6996bc1fd2c9f40ac7f1fbdecc00f8f313974eb1 (patch) | |
tree | 44ae13fc8837aa1c9da796aedcdd727dd84d87cc /test | |
parent | 873e1d68bb2eec9c018ac07085fb5c885c9e2b0c (diff) | |
download | tpm2-tss-6996bc1fd2c9f40ac7f1fbdecc00f8f313974eb1.tar.gz |
MU: Fix marshaling of TPM2Bs with sub types.
* The offset was not computed correctly if a NULL buffer was passed.
The TSS MU spec states: If the 'buffer' parameter is NULL the
implementation shall not write any marshaled data but the 'offset'
parameter shall be updated as as though it had.
* The unnecessary test of NULL buffer and not NULL offset was removed
and the corresponding unit test was adapted.
* Also a unit test which compares the result of NULL buffer and
not NULL buffer marshaling was added.
Signed-off-by: Juergen Repp <Juergen.Repp@sit.fraunhofer.de>
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/TPM2B-marshal.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/test/unit/TPM2B-marshal.c b/test/unit/TPM2B-marshal.c index deb5ba6b..301e2e2c 100644 --- a/test/unit/TPM2B-marshal.c +++ b/test/unit/TPM2B-marshal.c @@ -138,7 +138,28 @@ tpm2b_marshal_buffer_null_with_offset(void **state) offset = 10; rc = Tss2_MU_TPM2B_ECC_POINT_Marshal(&point, NULL, buffer_size, &offset); assert_int_equal (rc, TSS2_RC_SUCCESS); - assert_int_equal (offset, 10 + 2 + 2 + TPM2_MAX_ECC_KEY_BYTES + 2 + TPM2_MAX_ECC_KEY_BYTES); + assert_int_equal (offset, 10 + 2 + 2 + sizeof(value) + 2 + sizeof(value2)); + offset = 0; + rc = Tss2_MU_TPM2B_DIGEST_Marshal(&dgst, NULL, buffer_size, &offset); + assert_int_equal (rc, TSS2_RC_SUCCESS); + /* + * TSS MU spec states: + * If the 'buffer' parameter is NULL the implementation shall not write + * any marshaled data but the 'offset' parameter shall be updated as + * though it had. + * The offset of call with NULL and not NULL buffer will be compared. + */ + uint8_t buffer[offset]; + + size_t offset1 = 0; + rc = Tss2_MU_TPM2B_DIGEST_Marshal(&dgst, NULL, buffer_size, &offset1); + assert_int_equal (rc, TSS2_RC_SUCCESS); + + size_t offset2 = 0; + rc = Tss2_MU_TPM2B_DIGEST_Marshal(&dgst, buffer, buffer_size, &offset2); + assert_int_equal (rc, TSS2_RC_SUCCESS); + assert_int_equal(offset1, offset2); + } /* |