Blame SOURCES/0003-tpm2-Restore-original-value-if-unmarshalled-value-wa.patch

20abf0
From 5cc98a62dc6f204dcf5b87c2ee83ac742a6a319b Mon Sep 17 00:00:00 2001
20abf0
From: Stefan Berger <stefanb@linux.vnet.ibm.com>
20abf0
Date: Wed, 23 Jun 2021 20:54:44 -0400
20abf0
Subject: [PATCH 3/3] tpm2: Restore original value if unmarshalled value was
20abf0
 illegal
20abf0
20abf0
Restore the original value of the memory location where data from
20abf0
a stream was unmarshalled and the unmarshalled value was found to
20abf0
be illegal. The goal is to not keep illegal values in memory.
20abf0
20abf0
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
20abf0
---
20abf0
 src/tpm2/Unmarshal.c | 128 +++++++++++++++++++++++++++++++++++++++++++
20abf0
 1 file changed, 128 insertions(+)
20abf0
20abf0
diff --git a/src/tpm2/Unmarshal.c b/src/tpm2/Unmarshal.c
20abf0
index 8e7a9b7..e95d961 100644
20abf0
--- a/src/tpm2/Unmarshal.c
20abf0
+++ b/src/tpm2/Unmarshal.c
20abf0
@@ -165,6 +165,7 @@ TPM_RC
20abf0
 TPM_GENERATED_Unmarshal(TPM_GENERATED *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPM_GENERATED orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = UINT32_Unmarshal(target, buffer, size);  
20abf0
@@ -172,6 +173,7 @@ TPM_GENERATED_Unmarshal(TPM_GENERATED *target, BYTE **buffer, INT32 *size)
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	if (*target != TPM_GENERATED_VALUE) {
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -198,6 +200,7 @@ TPM_RC
20abf0
 TPM_ECC_CURVE_Unmarshal(TPM_ECC_CURVE *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPM_ECC_CURVE orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = UINT16_Unmarshal(target, buffer, size);
20abf0
@@ -216,6 +219,7 @@ TPM_ECC_CURVE_Unmarshal(TPM_ECC_CURVE *target, BYTE **buffer, INT32 *size)
20abf0
 	    break;
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_CURVE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -241,6 +245,7 @@ TPM_RC
20abf0
 TPM_CLOCK_ADJUST_Unmarshal(TPM_CLOCK_ADJUST *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPM_CLOCK_ADJUST orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = INT8_Unmarshal(target, buffer, size);  
20abf0
@@ -257,6 +262,7 @@ TPM_CLOCK_ADJUST_Unmarshal(TPM_CLOCK_ADJUST *target, BYTE **buffer, INT32 *size)
20abf0
 	    break;
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -268,6 +274,7 @@ TPM_RC
20abf0
 TPM_EO_Unmarshal(TPM_EO *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPM_EO orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = UINT16_Unmarshal(target, buffer, size);  
20abf0
@@ -289,6 +296,7 @@ TPM_EO_Unmarshal(TPM_EO *target, BYTE **buffer, INT32 *size)
20abf0
 	    break;
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -300,6 +308,7 @@ TPM_RC
20abf0
 TPM_ST_Unmarshal(TPM_ST *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPM_ST orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = UINT16_Unmarshal(target, buffer, size);  
20abf0
@@ -325,6 +334,7 @@ TPM_ST_Unmarshal(TPM_ST *target, BYTE **buffer, INT32 *size)
20abf0
 	    break;
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -336,6 +346,7 @@ TPM_RC
20abf0
 TPM_SU_Unmarshal(TPM_SU *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPM_SU orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = UINT16_Unmarshal(target, buffer, size);  
20abf0
@@ -347,6 +358,7 @@ TPM_SU_Unmarshal(TPM_SU *target, BYTE **buffer, INT32 *size)
20abf0
 	    break;
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -358,6 +370,7 @@ TPM_RC
20abf0
 TPM_SE_Unmarshal(TPM_SE *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPM_SE orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = UINT8_Unmarshal(target, buffer, size);  
20abf0
@@ -370,6 +383,7 @@ TPM_SE_Unmarshal(TPM_SE *target, BYTE **buffer, INT32 *size)
20abf0
 	    break;
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -381,6 +395,7 @@ TPM_RC
20abf0
 TPM_CAP_Unmarshal(TPM_CAP *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPM_CAP orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = UINT32_Unmarshal(target, buffer, size);  
20abf0
@@ -402,6 +417,7 @@ TPM_CAP_Unmarshal(TPM_CAP *target, BYTE **buffer, INT32 *size)
20abf0
 	    break;
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -452,6 +468,7 @@ TPM_RC
20abf0
 TPMA_ALGORITHM_Unmarshal(TPMA_ALGORITHM *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMA_ALGORITHM orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = UINT32_Unmarshal((UINT32 *)target, buffer, size); /* libtpms changed */
20abf0
@@ -459,6 +476,7 @@ TPMA_ALGORITHM_Unmarshal(TPMA_ALGORITHM *target, BYTE **buffer, INT32 *size)
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	if (*target & TPMA_ALGORITHM_reserved) {
20abf0
 	    rc = TPM_RC_RESERVED_BITS;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -470,6 +488,7 @@ TPM_RC
20abf0
 TPMA_OBJECT_Unmarshal(TPMA_OBJECT *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMA_OBJECT orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = UINT32_Unmarshal((UINT32 *)target, buffer, size); /* libtpms changed */
20abf0
@@ -477,6 +496,7 @@ TPMA_OBJECT_Unmarshal(TPMA_OBJECT *target, BYTE **buffer, INT32 *size)
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	if (*target & TPMA_OBJECT_reserved) {
20abf0
 	    rc = TPM_RC_RESERVED_BITS;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -488,6 +508,7 @@ TPM_RC
20abf0
 TPMA_SESSION_Unmarshal(TPMA_SESSION *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMA_SESSION orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = UINT8_Unmarshal((UINT8 *)target, buffer, size);  /* libtpms changed */
20abf0
@@ -495,6 +516,7 @@ TPMA_SESSION_Unmarshal(TPMA_SESSION *target, BYTE **buffer, INT32 *size)
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	if (*target & TPMA_SESSION_reserved) {
20abf0
 	    rc = TPM_RC_RESERVED_BITS;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -519,6 +541,7 @@ TPM_RC
20abf0
 TPMA_CC_Unmarshal(TPMA_CC *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMA_CC orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = UINT32_Unmarshal((UINT32 *)target, buffer, size); /* libtpms changed */
20abf0
@@ -526,6 +549,7 @@ TPMA_CC_Unmarshal(TPMA_CC *target, BYTE **buffer, INT32 *size)
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	if (*target & TPMA_CC_reserved) {
20abf0
 	    rc = TPM_RC_RESERVED_BITS;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -537,6 +561,7 @@ TPM_RC
20abf0
 TPMI_YES_NO_Unmarshal(TPMI_YES_NO *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_YES_NO orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = UINT8_Unmarshal(target, buffer, size);  
20abf0
@@ -548,6 +573,7 @@ TPMI_YES_NO_Unmarshal(TPMI_YES_NO *target, BYTE **buffer, INT32 *size)
20abf0
 	    break;
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -559,6 +585,7 @@ TPM_RC
20abf0
 TPMI_DH_OBJECT_Unmarshal(TPMI_DH_OBJECT *target, BYTE **buffer, INT32 *size, BOOL allowNull)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_DH_OBJECT orig_target = *target; // libtpms added
20abf0
     
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_HANDLE_Unmarshal(target, buffer, size);  
20abf0
@@ -571,6 +598,7 @@ TPMI_DH_OBJECT_Unmarshal(TPMI_DH_OBJECT *target, BYTE **buffer, INT32 *size, BOO
20abf0
 	    isNotPersistent &&
20abf0
 	    isNotLegalNull) {
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -582,6 +610,7 @@ TPM_RC
20abf0
 TPMI_DH_PARENT_Unmarshal(TPMI_DH_PARENT *target, BYTE **buffer, INT32 *size, BOOL allowNull)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_DH_PARENT orig_target = *target; // libtpms added
20abf0
     
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_HANDLE_Unmarshal(target, buffer, size);  
20abf0
@@ -600,6 +629,7 @@ TPMI_DH_PARENT_Unmarshal(TPMI_DH_PARENT *target, BYTE **buffer, INT32 *size, BOO
20abf0
 	    isNotEndorsement && 
20abf0
 	    isNotLegalNull) {
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -611,6 +641,7 @@ TPM_RC
20abf0
 TPMI_DH_PERSISTENT_Unmarshal(TPMI_DH_PERSISTENT *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_DH_PERSISTENT orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_HANDLE_Unmarshal(target, buffer, size);  
20abf0
@@ -619,6 +650,7 @@ TPMI_DH_PERSISTENT_Unmarshal(TPMI_DH_PERSISTENT *target, BYTE **buffer, INT32 *s
20abf0
 	BOOL isNotPersistent = (*target < PERSISTENT_FIRST) || (*target > PERSISTENT_LAST);
20abf0
 	if (isNotPersistent) {
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -630,6 +662,7 @@ TPM_RC
20abf0
 TPMI_DH_ENTITY_Unmarshal(TPMI_DH_ENTITY *target, BYTE **buffer, INT32 *size, BOOL allowNull)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_DH_ENTITY orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_HANDLE_Unmarshal(target, buffer, size);  
20abf0
@@ -656,6 +689,7 @@ TPMI_DH_ENTITY_Unmarshal(TPMI_DH_ENTITY *target, BYTE **buffer, INT32 *size, BOO
20abf0
 	    isNotAuth &&
20abf0
 	    isNotLegalNull) {
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -667,6 +701,7 @@ TPM_RC
20abf0
 TPMI_DH_PCR_Unmarshal(TPMI_DH_PCR *target, BYTE **buffer, INT32 *size, BOOL allowNull)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_DH_PCR orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_HANDLE_Unmarshal(target, buffer, size);  
20abf0
@@ -677,6 +712,7 @@ TPMI_DH_PCR_Unmarshal(TPMI_DH_PCR *target, BYTE **buffer, INT32 *size, BOOL allo
20abf0
 	if (isNotPcr &&
20abf0
 	    isNotLegalNull) {
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -688,6 +724,7 @@ TPM_RC
20abf0
 TPMI_SH_AUTH_SESSION_Unmarshal(TPMI_SH_AUTH_SESSION *target, BYTE **buffer, INT32 *size, BOOL allowPwd)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_SH_AUTH_SESSION orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_HANDLE_Unmarshal(target, buffer, size);  
20abf0
@@ -700,6 +737,7 @@ TPMI_SH_AUTH_SESSION_Unmarshal(TPMI_SH_AUTH_SESSION *target, BYTE **buffer, INT3
20abf0
 	    isNotPolicySession &&
20abf0
 	    isNotLegalPwd) {
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -711,6 +749,7 @@ TPM_RC
20abf0
 TPMI_SH_HMAC_Unmarshal(TPMI_SH_HMAC *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_SH_HMAC orig_target = *target; // libtpms added
20abf0
     
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_HANDLE_Unmarshal(target, buffer, size);  
20abf0
@@ -719,6 +758,7 @@ TPMI_SH_HMAC_Unmarshal(TPMI_SH_HMAC *target, BYTE **buffer, INT32 *size)
20abf0
 	BOOL isNotHmacSession = (*target < HMAC_SESSION_FIRST ) || (*target > HMAC_SESSION_LAST);
20abf0
 	if (isNotHmacSession) {
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -730,6 +770,7 @@ TPM_RC
20abf0
 TPMI_SH_POLICY_Unmarshal(TPMI_SH_POLICY *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_SH_POLICY orig_target = *target; // libtpms added
20abf0
     
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_HANDLE_Unmarshal(target, buffer, size);  
20abf0
@@ -738,6 +779,7 @@ TPMI_SH_POLICY_Unmarshal(TPMI_SH_POLICY *target, BYTE **buffer, INT32 *size)
20abf0
 	BOOL isNotPolicySession = (*target < POLICY_SESSION_FIRST) || (*target > POLICY_SESSION_LAST);
20abf0
 	if (isNotPolicySession) {
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -749,6 +791,7 @@ TPM_RC
20abf0
 TPMI_DH_CONTEXT_Unmarshal(TPMI_DH_CONTEXT *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_DH_CONTEXT orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_HANDLE_Unmarshal(target, buffer, size);  
20abf0
@@ -761,6 +804,7 @@ TPMI_DH_CONTEXT_Unmarshal(TPMI_DH_CONTEXT *target, BYTE **buffer, INT32 *size)
20abf0
 	    isNotPolicySession &&
20abf0
 	    isNotTransient) {
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -772,6 +816,7 @@ TPM_RC
20abf0
 TPMI_DH_SAVED_Unmarshal(TPMI_DH_SAVED *target, BYTE **buffer, INT32 *size, BOOL allowNull)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_DH_SAVED orig_target = *target; // libtpms added
20abf0
     allowNull = allowNull;
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
@@ -789,6 +834,7 @@ TPMI_DH_SAVED_Unmarshal(TPMI_DH_SAVED *target, BYTE **buffer, INT32 *size, BOOL
20abf0
 	    isNotSequenceObject &&
20abf0
 	    isNotTransientStClear) {
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -800,6 +846,7 @@ TPM_RC
20abf0
 TPMI_RH_HIERARCHY_Unmarshal(TPMI_RH_HIERARCHY *target, BYTE **buffer, INT32 *size, BOOL allowNull)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_RH_HIERARCHY orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_HANDLE_Unmarshal(target, buffer, size);  
20abf0
@@ -816,6 +863,7 @@ TPMI_RH_HIERARCHY_Unmarshal(TPMI_RH_HIERARCHY *target, BYTE **buffer, INT32 *siz
20abf0
 	    }
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -827,6 +875,7 @@ TPM_RC
20abf0
 TPMI_RH_ENABLES_Unmarshal(TPMI_RH_ENABLES *target, BYTE **buffer, INT32 *size, BOOL allowNull)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_RH_ENABLES orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_HANDLE_Unmarshal(target, buffer, size);  
20abf0
@@ -844,6 +893,7 @@ TPMI_RH_ENABLES_Unmarshal(TPMI_RH_ENABLES *target, BYTE **buffer, INT32 *size, B
20abf0
 	    }
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -855,6 +905,7 @@ TPM_RC
20abf0
 TPMI_RH_HIERARCHY_AUTH_Unmarshal(TPMI_RH_HIERARCHY_AUTH *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_RH_HIERARCHY_AUTH orig_target = *target; // libtpms added
20abf0
     
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_HANDLE_Unmarshal(target, buffer, size);  
20abf0
@@ -868,6 +919,7 @@ TPMI_RH_HIERARCHY_AUTH_Unmarshal(TPMI_RH_HIERARCHY_AUTH *target, BYTE **buffer,
20abf0
 	    break;
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -879,6 +931,7 @@ TPM_RC
20abf0
 TPMI_RH_HIERARCHY_POLICY_Unmarshal(TPMI_RH_HIERARCHY_POLICY *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_RH_HIERARCHY_POLICY orig_target = *target; // libtpms added
20abf0
     
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_HANDLE_Unmarshal(target, buffer, size);  
20abf0
@@ -895,6 +948,7 @@ TPMI_RH_HIERARCHY_POLICY_Unmarshal(TPMI_RH_HIERARCHY_POLICY *target, BYTE **buff
20abf0
 		  BOOL isNotHP =  (*target < TPM_RH_ACT_0) || (*target > TPM_RH_ACT_F);
20abf0
 		  if (isNotHP) {
20abf0
 		      rc = TPM_RC_VALUE;
20abf0
+		      *target = orig_target; // libtpms added
20abf0
 		  }
20abf0
 	      }
20abf0
 	}
20abf0
@@ -908,6 +962,7 @@ TPM_RC
20abf0
 TPMI_RH_PLATFORM_Unmarshal(TPMI_RH_PLATFORM *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_RH_PLATFORM orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_HANDLE_Unmarshal(target, buffer, size);  
20abf0
@@ -918,6 +973,7 @@ TPMI_RH_PLATFORM_Unmarshal(TPMI_RH_PLATFORM *target, BYTE **buffer, INT32 *size)
20abf0
 	    break;
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -929,6 +985,7 @@ TPM_RC
20abf0
 TPMI_RH_ENDORSEMENT_Unmarshal(TPMI_RH_ENDORSEMENT *target, BYTE **buffer, INT32 *size, BOOL allowNull)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_RH_ENDORSEMENT orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_HANDLE_Unmarshal(target, buffer, size);  
20abf0
@@ -943,6 +1000,7 @@ TPMI_RH_ENDORSEMENT_Unmarshal(TPMI_RH_ENDORSEMENT *target, BYTE **buffer, INT32
20abf0
 	    }
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -954,6 +1012,7 @@ TPM_RC
20abf0
 TPMI_RH_PROVISION_Unmarshal(TPMI_RH_PROVISION *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_RH_PROVISION orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_HANDLE_Unmarshal(target, buffer, size);  
20abf0
@@ -965,6 +1024,7 @@ TPMI_RH_PROVISION_Unmarshal(TPMI_RH_PROVISION *target, BYTE **buffer, INT32 *siz
20abf0
 	    break;
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -976,6 +1036,7 @@ TPM_RC
20abf0
 TPMI_RH_CLEAR_Unmarshal(TPMI_RH_CLEAR *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_RH_CLEAR orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_HANDLE_Unmarshal(target, buffer, size);  
20abf0
@@ -987,6 +1048,7 @@ TPMI_RH_CLEAR_Unmarshal(TPMI_RH_CLEAR *target, BYTE **buffer, INT32 *size)
20abf0
 	    break;
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -998,6 +1060,7 @@ TPM_RC
20abf0
 TPMI_RH_NV_AUTH_Unmarshal(TPMI_RH_NV_AUTH *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_RH_NV_AUTH orig_target = *target; // libtpms added
20abf0
     
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_HANDLE_Unmarshal(target, buffer, size);  
20abf0
@@ -1012,6 +1075,7 @@ TPMI_RH_NV_AUTH_Unmarshal(TPMI_RH_NV_AUTH *target, BYTE **buffer, INT32 *size)
20abf0
 		  BOOL isNotNv = (*target < NV_INDEX_FIRST) || (*target > NV_INDEX_LAST);
20abf0
 		  if (isNotNv) {
20abf0
 		      rc = TPM_RC_VALUE;
20abf0
+		      *target = orig_target; // libtpms added
20abf0
 		  }
20abf0
 	      }
20abf0
 	}
20abf0
@@ -1025,6 +1089,7 @@ TPM_RC
20abf0
 TPMI_RH_LOCKOUT_Unmarshal(TPMI_RH_LOCKOUT *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_RH_LOCKOUT orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_HANDLE_Unmarshal(target, buffer, size);  
20abf0
@@ -1035,6 +1100,7 @@ TPMI_RH_LOCKOUT_Unmarshal(TPMI_RH_LOCKOUT *target, BYTE **buffer, INT32 *size)
20abf0
 	    break;
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -1046,6 +1112,7 @@ TPM_RC
20abf0
 TPMI_RH_NV_INDEX_Unmarshal(TPMI_RH_NV_INDEX *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_RH_NV_INDEX orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_HANDLE_Unmarshal(target, buffer, size);  
20abf0
@@ -1054,6 +1121,7 @@ TPMI_RH_NV_INDEX_Unmarshal(TPMI_RH_NV_INDEX *target, BYTE **buffer, INT32 *size)
20abf0
 	BOOL isNotNv = (*target < NV_INDEX_FIRST) || (*target > NV_INDEX_LAST);
20abf0
 	if (isNotNv) {
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -1065,6 +1133,7 @@ TPM_RC
20abf0
 TPMI_RH_AC_Unmarshal(TPMI_RH_AC *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_RH_AC orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_HANDLE_Unmarshal(target, buffer, size);  
20abf0
@@ -1073,6 +1142,7 @@ TPMI_RH_AC_Unmarshal(TPMI_RH_AC *target, BYTE **buffer, INT32 *size)
20abf0
 	BOOL isNotAC = (*target < AC_FIRST) || (*target > AC_LAST);
20abf0
 	if (isNotAC) {
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -1084,6 +1154,7 @@ TPM_RC
20abf0
 TPMI_RH_ACT_Unmarshal( TPMI_RH_ACT *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_RH_ACT orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_HANDLE_Unmarshal(target, buffer, size);  
20abf0
@@ -1092,6 +1163,7 @@ TPMI_RH_ACT_Unmarshal( TPMI_RH_ACT *target, BYTE **buffer, INT32 *size)
20abf0
 	BOOL isNotACT = (*target < TPM_RH_ACT_0) || (*target > TPM_RH_ACT_F);
20abf0
 	if (isNotACT) {
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -1103,6 +1175,7 @@ TPM_RC
20abf0
 TPMI_ALG_HASH_Unmarshal(TPMI_ALG_HASH *target, BYTE **buffer, INT32 *size, BOOL allowNull)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_ALG_HASH orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_ALG_ID_Unmarshal(target, buffer, size);  
20abf0
@@ -1131,6 +1204,7 @@ TPMI_ALG_HASH_Unmarshal(TPMI_ALG_HASH *target, BYTE **buffer, INT32 *size, BOOL
20abf0
 	    }
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_HASH;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -1142,6 +1216,7 @@ TPM_RC
20abf0
 TPMI_ALG_SYM_Unmarshal(TPMI_ALG_SYM *target, BYTE **buffer, INT32 *size, BOOL allowNull)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_ALG_SYM orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_ALG_ID_Unmarshal(target, buffer, size);  
20abf0
@@ -1170,6 +1245,7 @@ TPMI_ALG_SYM_Unmarshal(TPMI_ALG_SYM *target, BYTE **buffer, INT32 *size, BOOL al
20abf0
 	    }
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_SYMMETRIC;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -1181,6 +1257,7 @@ TPM_RC
20abf0
 TPMI_ALG_SYM_OBJECT_Unmarshal(TPMI_ALG_SYM_OBJECT *target, BYTE **buffer, INT32 *size, BOOL allowNull)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_ALG_SYM_OBJECT orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_ALG_ID_Unmarshal(target, buffer, size);  
20abf0
@@ -1206,6 +1283,7 @@ TPMI_ALG_SYM_OBJECT_Unmarshal(TPMI_ALG_SYM_OBJECT *target, BYTE **buffer, INT32
20abf0
 	    }
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_SYMMETRIC;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -1217,6 +1295,7 @@ TPM_RC
20abf0
 TPMI_ALG_SYM_MODE_Unmarshal(TPMI_ALG_SYM_MODE *target, BYTE **buffer, INT32 *size, BOOL allowNull)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_ALG_SYM_MODE orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_ALG_ID_Unmarshal(target, buffer, size);  
20abf0
@@ -1248,6 +1327,7 @@ TPMI_ALG_SYM_MODE_Unmarshal(TPMI_ALG_SYM_MODE *target, BYTE **buffer, INT32 *siz
20abf0
 	    }
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_MODE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -1259,6 +1339,7 @@ TPM_RC
20abf0
 TPMI_ALG_KDF_Unmarshal(TPMI_ALG_KDF *target, BYTE **buffer, INT32 *size, BOOL allowNull)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_ALG_KDF orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_ALG_ID_Unmarshal(target, buffer, size);  
20abf0
@@ -1284,6 +1365,7 @@ TPMI_ALG_KDF_Unmarshal(TPMI_ALG_KDF *target, BYTE **buffer, INT32 *size, BOOL al
20abf0
 	    }
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_KDF;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -1295,6 +1377,7 @@ TPM_RC
20abf0
 TPMI_ALG_SIG_SCHEME_Unmarshal(TPMI_ALG_SIG_SCHEME *target, BYTE **buffer, INT32 *size, BOOL allowNull)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_ALG_SIG_SCHEME orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_ALG_ID_Unmarshal(target, buffer, size);  
20abf0
@@ -1329,6 +1412,7 @@ TPMI_ALG_SIG_SCHEME_Unmarshal(TPMI_ALG_SIG_SCHEME *target, BYTE **buffer, INT32
20abf0
 	    }
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_SCHEME;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -1340,6 +1424,7 @@ TPM_RC
20abf0
 TPMI_ECC_KEY_EXCHANGE_Unmarshal(TPMI_ECC_KEY_EXCHANGE *target, BYTE **buffer, INT32 *size, BOOL allowNull)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_ECC_KEY_EXCHANGE orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_ALG_ID_Unmarshal(target, buffer, size);  
20abf0
@@ -1362,6 +1447,7 @@ TPMI_ECC_KEY_EXCHANGE_Unmarshal(TPMI_ECC_KEY_EXCHANGE *target, BYTE **buffer, IN
20abf0
 	    }
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_SCHEME;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -1374,6 +1460,7 @@ TPM_RC
20abf0
 TPMI_ST_COMMAND_TAG_Unmarshal(TPMI_ST_COMMAND_TAG *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_ST_COMMAND_TAG orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_ST_Unmarshal(target, buffer, size);  
20abf0
@@ -1385,6 +1472,7 @@ TPMI_ST_COMMAND_TAG_Unmarshal(TPMI_ST_COMMAND_TAG *target, BYTE **buffer, INT32
20abf0
 	    break;
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_BAD_TAG;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -1396,6 +1484,7 @@ TPM_RC
20abf0
 TPMI_ALG_MAC_SCHEME_Unmarshal(TPMI_ALG_MAC_SCHEME *target, BYTE **buffer, INT32 *size, BOOL allowNull)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_ALG_MAC_SCHEME orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_ALG_ID_Unmarshal(target, buffer, size);  
20abf0
@@ -1427,6 +1516,7 @@ TPMI_ALG_MAC_SCHEME_Unmarshal(TPMI_ALG_MAC_SCHEME *target, BYTE **buffer, INT32
20abf0
 	    }
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_SYMMETRIC;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -1438,6 +1528,7 @@ TPM_RC
20abf0
 TPMI_ALG_CIPHER_MODE_Unmarshal(TPMI_ALG_CIPHER_MODE*target, BYTE **buffer, INT32 *size, BOOL allowNull)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_ALG_CIPHER_MODE orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_ALG_ID_Unmarshal(target, buffer, size);  
20abf0
@@ -1466,6 +1557,7 @@ TPMI_ALG_CIPHER_MODE_Unmarshal(TPMI_ALG_CIPHER_MODE*target, BYTE **buffer, INT32
20abf0
 	    }
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_MODE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -1702,6 +1794,7 @@ TPM_RC
20abf0
 TPMT_TK_CREATION_Unmarshal(TPMT_TK_CREATION *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPM_ST orig_tag = target->tag; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_ST_Unmarshal(&target->tag, buffer, size);
20abf0
@@ -1709,6 +1802,7 @@ TPMT_TK_CREATION_Unmarshal(TPMT_TK_CREATION *target, BYTE **buffer, INT32 *size)
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	if (target->tag != TPM_ST_CREATION) {
20abf0
 	    rc = TPM_RC_TAG;
20abf0
+	    target->tag = orig_tag; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
@@ -1726,6 +1820,7 @@ TPM_RC
20abf0
 TPMT_TK_VERIFIED_Unmarshal(TPMT_TK_VERIFIED *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPM_ST orig_tag = target->tag; // libtpms added
20abf0
     
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_ST_Unmarshal(&target->tag, buffer, size);
20abf0
@@ -1733,6 +1828,7 @@ TPMT_TK_VERIFIED_Unmarshal(TPMT_TK_VERIFIED *target, BYTE **buffer, INT32 *size)
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	if (target->tag != TPM_ST_VERIFIED) {
20abf0
 	    rc = TPM_RC_TAG;
20abf0
+	    target->tag = orig_tag; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
@@ -1750,6 +1846,7 @@ TPM_RC
20abf0
 TPMT_TK_AUTH_Unmarshal(TPMT_TK_AUTH *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPM_ST orig_tag = target->tag; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_ST_Unmarshal(&target->tag, buffer, size);
20abf0
@@ -1758,6 +1855,7 @@ TPMT_TK_AUTH_Unmarshal(TPMT_TK_AUTH *target, BYTE **buffer, INT32 *size)
20abf0
 	if ((target->tag != TPM_ST_AUTH_SIGNED) &&
20abf0
 	    (target->tag != TPM_ST_AUTH_SECRET)) {
20abf0
 	    rc = TPM_RC_TAG;
20abf0
+	    target->tag = orig_tag; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
@@ -1775,6 +1873,7 @@ TPM_RC
20abf0
 TPMT_TK_HASHCHECK_Unmarshal(TPMT_TK_HASHCHECK *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPM_ST orig_tag = target->tag; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_ST_Unmarshal(&target->tag, buffer, size);
20abf0
@@ -1782,6 +1881,7 @@ TPMT_TK_HASHCHECK_Unmarshal(TPMT_TK_HASHCHECK *target, BYTE **buffer, INT32 *siz
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	if (target->tag != TPM_ST_HASHCHECK) {
20abf0
 	    rc = TPM_RC_TAG;
20abf0
+	    target->tag = orig_tag; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
@@ -2380,6 +2480,7 @@ TPM_RC
20abf0
 TPMI_ST_ATTEST_Unmarshal(TPMI_ST_ATTEST *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_ST_ATTEST orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_ST_Unmarshal(target, buffer, size);
20abf0
@@ -2396,6 +2497,7 @@ TPMI_ST_ATTEST_Unmarshal(TPMI_ST_ATTEST *target, BYTE **buffer, INT32 *size)
20abf0
 	    break;
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_SELECTOR;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -2490,6 +2592,7 @@ TPM_RC
20abf0
 TPMI_AES_KEY_BITS_Unmarshal(TPMI_AES_KEY_BITS *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_AES_KEY_BITS orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_KEY_BITS_Unmarshal(target, buffer, size);  
20abf0
@@ -2501,6 +2604,7 @@ TPMI_AES_KEY_BITS_Unmarshal(TPMI_AES_KEY_BITS *target, BYTE **buffer, INT32 *siz
20abf0
 	    break;
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -2512,6 +2616,7 @@ TPM_RC
20abf0
 TPMI_CAMELLIA_KEY_BITS_Unmarshal(TPMI_CAMELLIA_KEY_BITS *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_CAMELLIA_KEY_BITS orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_KEY_BITS_Unmarshal(target, buffer, size);  
20abf0
@@ -2522,6 +2627,7 @@ TPMI_CAMELLIA_KEY_BITS_Unmarshal(TPMI_CAMELLIA_KEY_BITS *target, BYTE **buffer,
20abf0
 	    break;
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -2533,6 +2639,7 @@ TPM_RC
20abf0
 TPMI_SM4_KEY_BITS_Unmarshal(TPMI_SM4_KEY_BITS *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_SM4_KEY_BITS orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_KEY_BITS_Unmarshal(target, buffer, size);  
20abf0
@@ -2543,6 +2650,7 @@ TPMI_SM4_KEY_BITS_Unmarshal(TPMI_SM4_KEY_BITS *target, BYTE **buffer, INT32 *siz
20abf0
 	    break;
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -2554,6 +2662,7 @@ TPM_RC
20abf0
 TPMI_TDES_KEY_BITS_Unmarshal(TPMI_SM4_KEY_BITS *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_SM4_KEY_BITS orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_KEY_BITS_Unmarshal(target, buffer, size);
20abf0
@@ -2565,6 +2674,7 @@ TPMI_TDES_KEY_BITS_Unmarshal(TPMI_SM4_KEY_BITS *target, BYTE **buffer, INT32 *si
20abf0
 	    break;
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -2837,6 +2947,7 @@ TPM_RC
20abf0
 TPMI_ALG_KEYEDHASH_SCHEME_Unmarshal(TPMI_ALG_KEYEDHASH_SCHEME *target, BYTE **buffer, INT32 *size, BOOL allowNull)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_ALG_KEYEDHASH_SCHEME orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_ALG_ID_Unmarshal(target, buffer, size);  
20abf0
@@ -2856,6 +2967,7 @@ TPMI_ALG_KEYEDHASH_SCHEME_Unmarshal(TPMI_ALG_KEYEDHASH_SCHEME *target, BYTE **bu
20abf0
 	    }
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -3240,6 +3352,7 @@ TPM_RC
20abf0
 TPMI_ALG_ASYM_SCHEME_Unmarshal(TPMI_ALG_ASYM_SCHEME *target, BYTE **buffer, INT32 *size, BOOL allowNull)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_ALG_ASYM_SCHEME orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_ALG_ID_Unmarshal(target, buffer, size);  
20abf0
@@ -3283,6 +3396,7 @@ TPMI_ALG_ASYM_SCHEME_Unmarshal(TPMI_ALG_ASYM_SCHEME *target, BYTE **buffer, INT3
20abf0
 	    }
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -3361,6 +3475,7 @@ TPM_RC
20abf0
 TPMI_ALG_RSA_SCHEME_Unmarshal(TPMI_ALG_RSA_SCHEME *target, BYTE **buffer, INT32 *size, BOOL allowNull)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_ALG_RSA_SCHEME orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_ALG_ID_Unmarshal(target, buffer, size);  
20abf0
@@ -3386,6 +3501,7 @@ TPMI_ALG_RSA_SCHEME_Unmarshal(TPMI_ALG_RSA_SCHEME *target, BYTE **buffer, INT32
20abf0
 	    }
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -3413,6 +3529,7 @@ TPM_RC
20abf0
 TPMI_ALG_RSA_DECRYPT_Unmarshal(TPMI_ALG_RSA_DECRYPT *target, BYTE **buffer, INT32 *size, BOOL allowNull)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_ALG_RSA_DECRYPT orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_ALG_ID_Unmarshal(target, buffer, size);  
20abf0
@@ -3432,6 +3549,7 @@ TPMI_ALG_RSA_DECRYPT_Unmarshal(TPMI_ALG_RSA_DECRYPT *target, BYTE **buffer, INT3
20abf0
 	    }
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -3472,6 +3590,7 @@ TPM_RC
20abf0
 TPMI_RSA_KEY_BITS_Unmarshal(TPMI_RSA_KEY_BITS *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_RSA_KEY_BITS orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_KEY_BITS_Unmarshal(target, buffer, size);  
20abf0
@@ -3484,6 +3603,7 @@ TPMI_RSA_KEY_BITS_Unmarshal(TPMI_RSA_KEY_BITS *target, BYTE **buffer, INT32 *siz
20abf0
 	    break;
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_VALUE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -3568,6 +3688,7 @@ TPM_RC
20abf0
 TPMI_ALG_ECC_SCHEME_Unmarshal(TPMI_ALG_ECC_SCHEME *target, BYTE **buffer, INT32 *size, BOOL allowNull)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_ALG_ECC_SCHEME orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_ALG_ID_Unmarshal(target, buffer, size);  
20abf0
@@ -3599,6 +3720,7 @@ TPMI_ALG_ECC_SCHEME_Unmarshal(TPMI_ALG_ECC_SCHEME *target, BYTE **buffer, INT32
20abf0
 	    }
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_SCHEME;
20abf0
+	    *target = orig_target; //  libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -3610,6 +3732,7 @@ TPM_RC
20abf0
 TPMI_ECC_CURVE_Unmarshal(TPMI_ECC_CURVE *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_ECC_CURVE orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_ECC_CURVE_Unmarshal(target, buffer, size);  
20abf0
@@ -3646,6 +3769,7 @@ TPMI_ECC_CURVE_Unmarshal(TPMI_ECC_CURVE *target, BYTE **buffer, INT32 *size)
20abf0
 	    break;
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_CURVE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -3860,6 +3984,7 @@ TPM_RC
20abf0
 TPMI_ALG_PUBLIC_Unmarshal(TPMI_ALG_PUBLIC *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMI_ALG_PUBLIC orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = TPM_ALG_ID_Unmarshal(target, buffer, size);  
20abf0
@@ -3881,6 +4006,7 @@ TPMI_ALG_PUBLIC_Unmarshal(TPMI_ALG_PUBLIC *target, BYTE **buffer, INT32 *size)
20abf0
 	    break;
20abf0
 	  default:
20abf0
 	    rc = TPM_RC_TYPE;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
@@ -4215,6 +4341,7 @@ TPM_RC
20abf0
 TPMA_NV_Unmarshal(TPMA_NV *target, BYTE **buffer, INT32 *size)
20abf0
 {
20abf0
     TPM_RC rc = TPM_RC_SUCCESS;
20abf0
+    TPMA_NV orig_target = *target; // libtpms added
20abf0
 
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	rc = UINT32_Unmarshal((UINT32 *)target, buffer, size);  /* libtpms changed */
20abf0
@@ -4222,6 +4349,7 @@ TPMA_NV_Unmarshal(TPMA_NV *target, BYTE **buffer, INT32 *size)
20abf0
     if (rc == TPM_RC_SUCCESS) {
20abf0
 	if (*target & TPMA_NV_RESERVED) {
20abf0
 	    rc = TPM_RC_RESERVED_BITS;
20abf0
+	    *target = orig_target; // libtpms added
20abf0
 	}
20abf0
     }
20abf0
     return rc;
20abf0
-- 
20abf0
2.29.0
20abf0