]> git.proxmox.com Git - swtpm.git/commitdiff
swtpm: Refactor existing function to use new tpmlib_get_cmd_ordinal()
authorStefan Berger <stefanb@linux.ibm.com>
Mon, 30 May 2022 14:47:12 +0000 (10:47 -0400)
committerStefan Berger <stefanb@us.ibm.com>
Thu, 18 Aug 2022 13:50:16 +0000 (09:50 -0400)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
src/swtpm/tpmlib.c

index e8632f2f26566676f3ef9687b7f594740301ee09..b1119bdfe4b2eccc8e915753137831e96be3ac59 100644 (file)
@@ -169,14 +169,11 @@ uint32_t tpmlib_get_cmd_ordinal(const unsigned char *request, size_t req_len)
 bool tpmlib_is_request_cancelable(TPMLIB_TPMVersion tpmversion,
                                   const unsigned char *request, size_t req_len)
 {
-    struct tpm_req_header *hdr;
-    uint32_t ordinal;
 
-    if (req_len < sizeof(struct tpm_req_header))
-        return false;
+    uint32_t ordinal = tpmlib_get_cmd_ordinal(request, req_len);
 
-    hdr = (struct tpm_req_header *)request;
-    ordinal = be32toh(hdr->ordinal);
+    if (ordinal == TPM_ORDINAL_NONE)
+        return false;
 
     if (tpmversion == TPMLIB_TPM_VERSION_2)
         return (ordinal == TPMLIB_TPM2_CC_CreatePrimary ||