tpm12: Get rid of usage of sprintf and use snprintf instead

Get rid of the usage of an sprintf and use snprintf instead. In this
case the buffer is 128, so big enough to not cause problems, though.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
Stefan Berger 2019-10-17 10:43:43 -04:00 committed by Stefan Berger
parent 7bd2fb0d42
commit 57d628a5ce

View File

@ -627,8 +627,14 @@ TPM_RESULT TPM_Process_GetTestResult(tpm_state_t *tpm_state,
}
/* for now, just return the state of shutdown as a printable string */
if (returnCode == TPM_SUCCESS) {
/* cast because TPM_SIZED_BUFFER is typically unsigned (binary) but sprintf expects char */
outData.size = sprintf((char *)(outData.buffer), "Shutdown %08x\n", tpm_state->testState);
size_t len = outData.size;
/* cast because TPM_SIZED_BUFFER is typically unsigned (binary) but snprintf expects char */
outData.size = snprintf((char *)(outData.buffer), len,
"Shutdown %08x\n", tpm_state->testState);
if (outData.size >= len) {
printf("TPM_Process_GetTestResult: Error (fatal), buffer too small\n");
returnCode = TPM_FAIL;
}
}
/*
response