swtpm: Handle case where unknown blobtype is given (Coverity)

Handle the case where an unknown blobtype is given and therefore
cannot be translated to a filename and blobname is NULL. Previously
this would have lead to an error when trying to read the file, now
we handle the failure case earlier.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
Stefan Berger 2022-05-25 15:47:04 -04:00 committed by Stefan Berger
parent bfa79e91f2
commit 760ec8ea96

View File

@ -131,7 +131,7 @@ int ctrlchannel_set_client_fd(struct ctrlchannel *cc, int fd)
static int ctrlchannel_return_state(ptm_getstate *pgs, int fd)
{
uint32_t blobtype = be32toh(pgs->u.req.type);
const char *blobname = tpmlib_get_blobname(blobtype);
const char *blobname;
uint32_t tpm_number = 0;
unsigned char *blob = NULL;
uint32_t blob_length = 0, return_length;
@ -145,7 +145,11 @@ static int ctrlchannel_return_state(ptm_getstate *pgs, int fd)
struct iovec iov[2];
int iovcnt, n;
if (blobtype == PTM_BLOB_TYPE_VOLATILE)
blobname = tpmlib_get_blobname(blobtype);
if (!blobname)
res = TPM_FAIL;
if (res == 0 && blobtype == PTM_BLOB_TYPE_VOLATILE)
res = SWTPM_NVRAM_Store_Volatile();
if (res == 0)