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 <[email protected]>
Commit-Queue: Jocelyn Bohr <[email protected]>
Tested-by: Jocelyn Bohr <[email protected]>
diff --git a/PolicyLocality.c b/PolicyLocality.c
index 2114aa1..3e513ee 100644
--- a/PolicyLocality.c
+++ b/PolicyLocality.c
@@ -25,6 +25,7 @@
BYTE prevSetting[sizeof(TPMA_LOCALITY)];
UINT32 marshalSize;
BYTE *buffer;
+ INT32 bufferSize;
TPM_CC commandCode = TPM_CC_PolicyLocality;
HASH_STATE hashState;
@@ -35,7 +36,8 @@
// Get new locality setting in canonical form
buffer = marshalBuffer;
- marshalSize = TPMA_LOCALITY_Marshal(&in->locality, &buffer, NULL);
+ bufferSize = sizeof(TPMA_LOCALITY);
+ marshalSize = TPMA_LOCALITY_Marshal(&in->locality, &buffer, &bufferSize);
// Its an error if the locality parameter is zero
if(marshalBuffer[0] == 0)
@@ -43,7 +45,8 @@
// Get existing locality setting in canonical form
buffer = prevSetting;
- TPMA_LOCALITY_Marshal(&session->commandLocality, &buffer, NULL);
+ bufferSize = sizeof(TPMA_LOCALITY);
+ TPMA_LOCALITY_Marshal(&session->commandLocality, &buffer, &bufferSize);
// If the locality has previously been set
if( prevSetting[0] != 0