BIO *b64, *bmem;
unsigned char *res = NULL;
int n;
- TPM_RESULT rc;
b64 = BIO_new(BIO_f_base64());
if (!b64) {
bmem = BIO_push(b64, bmem);
BIO_set_flags(bmem, BIO_FLAGS_BASE64_NO_NL);
- rc = TPM_Malloc(&res, outputlen);
- if (rc != TPM_SUCCESS) {
+ res = malloc(outputlen);
+ if (!res) {
+ TPMLIB_LogError("Could not allocate %u bytes.\n", outputlen);
goto cleanup;
}
n = BIO_read(bmem, res, outputlen);
if (n <= 0) {
- TPM_Free(res);
+ free(res);
res = NULL;
goto cleanup;
}
end++;
- if (TPM_Malloc((unsigned char **)&input, end - start + 1) != TPM_SUCCESS)
+ input = malloc(end - start + 1);
+ if (!input) {
+ TPMLIB_LogError("Could not allocate %u bytes.\n",
+ (unsigned int)(end - start + 1));
return NULL;
+ }
/* copy from source string skipping '\n' and '\r' and using
'=' to calculate the exact length */
*is_empty_buffer = (*buflen == BUFLEN_EMPTY_BUFFER);
if (cached_blobs[st].buffer) {
- ret = TPM_Malloc(buffer, *buflen);
- if (ret == TPM_SUCCESS)
+ *buffer = malloc(*buflen);
+ if (!*buffer) {
+ TPMLIB_LogError("Could not allocate %u bytes.\n", *buflen);
+ ret = TPM_SIZE;
+ } else {
memcpy(*buffer, cached_blobs[st].buffer, *buflen);
+ }
} else {
*buffer = NULL;
}
int TPMLIB_LogPrintf(const char *format, ...);
void TPMLIB_LogPrintfA(unsigned int indent, const char *format, ...);
+#define TPMLIB_LogError(format, ...) \
+ TPMLIB_LogPrintfA(~0, "libtpms: "format, __VA_ARGS__)
#define TPMLIB_LogTPM12Error(format, ...) \
TPMLIB_LogPrintfA(~0, "libtpms/tpm12: "format, __VA_ARGS__)
return TPM_INVALID_POSTINIT;
if (ret == TPM_SUCCESS) {
- ret = TPM_Malloc((unsigned char **)&stream, buflen);
+ stream = malloc(buflen);
+ if (!stream) {
+ TPMLIB_LogError("Could not allocate %u bytes.\n", buflen);
+ ret = TPM_SIZE;
+ }
}
if (ret == TPM_SUCCESS) {
orig_stream = stream;
memcpy(stream, buffer, buflen);
- ret = TPM_Malloc((unsigned char **)&tpm_state, sizeof(tpm_state_t));
+ tpm_state = malloc(sizeof(tpm_state_t));
+ if (!tpm_state) {
+ TPMLIB_LogError("Could not allocated %zu bytes.\n",
+ sizeof(tpm_state_t));
+ ret = TPM_SIZE;
+ }
}
if (ret == TPM_SUCCESS) {