aboutsummaryrefslogtreecommitdiff
path: root/Object.c
diff options
context:
space:
mode:
authorJocelyn Bohr <bohr@chromium.org>2015-07-29 15:14:01 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-07-30 18:57:42 +0000
commit32be40450906cd2c80dee4a83204931f7f3a2daa (patch)
tree97c604edeaaa5834d4f4d870df23ef13b7876765 /Object.c
parent9edfbac6a36e07e1a7ccb2260b6f65d97b45fef8 (diff)
downloadtpm2-32be40450906cd2c80dee4a83204931f7f3a2daa.tar.gz
Remove instances of calling marshal functions with NULL pointer.
In the code scraped from the TCG TPM2.0 Library specification, there are several instances where the intent is to marshal data into a buffer, but NULL pointer is passed in as size. Part 4 section 4.2.3.1 states: "If size is a NULL pointer, then no data is marshaled and the routine will compute the size of the memory required to marshal the indicated type." Implying these usages are bugs. This CL removes all instances of passing in NULL as size to a Marshal function when the intent is to marshal data. TEST=$ sudo emerge tpm2 builds libtpm2.a. Currently this is the only test we have for the scraped code. BUG=none Change-Id: If7b2a60f6a8e875b4a6eceab513dc22325bf4999 Reviewed-on: https://chromium-review.googlesource.com/289647 Reviewed-by: Utkarsh Sanghi <usanghi@chromium.org> Commit-Queue: Jocelyn Bohr <bohr@chromium.org> Tested-by: Jocelyn Bohr <bohr@chromium.org>
Diffstat (limited to 'Object.c')
-rw-r--r--Object.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/Object.c b/Object.c
index b25de0c..5a16f8c 100644
--- a/Object.c
+++ b/Object.c
@@ -722,6 +722,7 @@ ObjectComputeName(
{
TPM2B_PUBLIC marshalBuffer;
BYTE *buffer; // auxiliary marshal buffer pointer
+ INT32 bufferSize;
HASH_STATE hashState; // hash state
// if the nameAlg is NULL then there is no name.
if(publicArea->nameAlg == TPM_ALG_NULL)
@@ -733,7 +734,8 @@ ObjectComputeName(
name->t.size = CryptStartHash(publicArea->nameAlg, &hashState);
// Marshal the public area into its canonical form
buffer = marshalBuffer.b.buffer;
- marshalBuffer.t.size = TPMT_PUBLIC_Marshal(publicArea, &buffer, NULL);
+ bufferSize = marshalBuffer.b.size;
+ marshalBuffer.t.size = TPMT_PUBLIC_Marshal(publicArea, &buffer, &bufferSize);
// Adding public area
CryptUpdateDigest2B(&hashState, &marshalBuffer.b);
// Complete hash leaving room for the name algorithm