fd = -1;
}
- TPM_Free(blob);
+ free(blob);
return fd;
}
uint32_t flags = be32toh(pss->u.req.state_flags);
TPM_BOOL is_encrypted = (flags & PTM_STATE_FLAG_ENCRYPTED) != 0;
- res = TPM_Malloc(&blob, blob_length);
- if (res)
+ blob = malloc(blob_length);
+ if (!blob) {
+ logprintf(STDERR_FILENO,
+ "Could not allocated %u bytes.\n", blob_length);
+ res = TPM_FAIL;
goto err_send_resp;
+ }
n -= offsetof(ptm_setstate, u.req.data);
/* n holds the number of available data bytes */
err_fd_broken:
- TPM_Free(blob);
+ free(blob);
return fd;
}
*/
static void cached_stateblob_free(void)
{
- TPM_Free(cached_stateblob.data);
+ free(cached_stateblob.data);
cached_stateblob.data = NULL;
cached_stateblob.data_length = 0;
}
{
TPM_RESULT res = 0;
static struct stateblob stateblob;
+ unsigned char *tmp;
if (stateblob.type != blobtype) {
/* new blob; clear old data */
- TPM_Free(stateblob.data);
+ free(stateblob.data);
stateblob.data = NULL;
stateblob.length = 0;
stateblob.type = blobtype;
}
/* append */
- res = TPM_Realloc(&stateblob.data, stateblob.length + length);
- if (res != 0) {
+ tmp = realloc(stateblob.data, stateblob.length + length);
+ if (!tmp) {
+ logprintf(STDERR_FILENO,
+ "Could not allocate %u bytes.\n", stateblob.length + length);
/* error */
- TPM_Free(stateblob.data);
+ free(stateblob.data);
stateblob.data = NULL;
stateblob.length = 0;
stateblob.type = 0;
- return res;
- }
+ return TPM_FAIL;
+ } else
+ stateblob.data = tmp;
memcpy(&stateblob.data[stateblob.length], data, length);
stateblob.length += length;
0 /* tpm_number */,
blobtype);
- TPM_Free(stateblob.data);
+ free(stateblob.data);
stateblob.data = NULL;
stateblob.length = 0;
stateblob.type = 0;
tpm_running = false;
- TPM_Free(ptm_response);
+ free(ptm_response);
ptm_response = NULL;
fuse_reply_ioctl(req, 0, &res, sizeof(res));
res = TPM_SUCCESS;
TPMLIB_Terminate();
- TPM_Free(ptm_response);
+ free(ptm_response);
ptm_response = NULL;
fuse_reply_ioctl(req, 0, &res, sizeof(res));
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
+#include <stdlib.h>
#include <string.h>
#include <poll.h>
#include <sys/stat.h>
max_command_length = tpmlib_get_tpm_property(TPMPROP_TPM_BUFFER_MAX);
- rc = TPM_Malloc(&command, max_command_length);
- if (rc != TPM_SUCCESS) {
+ command = malloc(max_command_length);
+ if (!command) {
logprintf(STDERR_FILENO, "Could not allocate %u bytes for buffer.\n",
max_command_length);
- return rc;
+ return TPM_FAIL;
}
connection_fd.fd = -1;
break;
}
- TPM_Free(rbuffer);
- TPM_Free(command);
+ free(rbuffer);
+ free(command);
if (ctrlclntfd >= 0)
close(ctrlclntfd);
#include <libtpms/tpm_memory.h>
#include "swtpm_aes.h"
+#include "logging.h"
#define printf(X ...)
printf(" TPM_SymmetricKeyData_Encrypt: Padded length %u pad length %u\n",
*encrypt_length, pad_length);
/* allocate memory for the encrypted response */
- rc = TPM_Malloc(encrypt_data, *encrypt_length);
+ *encrypt_data = malloc(*encrypt_length);
+ if (!*encrypt_data) {
+ logprintf(STDERR_FILENO,
+ "Could not allocated %u bytes.\n", *encrypt_length);
+ rc = TPM_SIZE;
+ }
}
/* allocate memory for the padded decrypted data */
if (rc == 0) {
- rc = TPM_Malloc(&decrypt_data_pad, *encrypt_length);
+ decrypt_data_pad = malloc(*encrypt_length);
+ if (!decrypt_data_pad) {
+ logprintf(STDERR_FILENO,
+ "Could not allocated %u bytes.\n", *encrypt_length);
+ rc = TPM_SIZE;
+ }
}
if (rc == 0) {
}
/* allocate memory for the padded decrypted data */
if (rc == 0) {
- rc = TPM_Malloc(decrypt_data, encrypt_length);
+ *decrypt_data = malloc(encrypt_length);
+ if (!*decrypt_data) {
+ logprintf(STDERR_FILENO,
+ "Could not allocated %u bytes.\n", encrypt_length);
+ rc = TPM_SIZE;
+ }
}
if (rc == 0) {
/* allocate a buffer for the actual data */
if ((rc == 0) && *length != 0) {
TPM_DEBUG(" SWTPM_NVRAM_LoadData: Reading %u bytes of data\n", *length);
- rc = TPM_Malloc(data, *length);
- if (rc != 0) {
+ *data = malloc(*length);
+ if (!*data) {
logprintf(STDERR_FILENO,
"SWTPM_NVRAM_LoadData: Error (fatal) allocating %u "
"bytes\n", *length);
TPM_DEBUG(" SWTPM_NVRAM_LoadData: Decrypted %u bytes of "
"data to %u bytes.\n",
*length, decrypt_length);
- TPM_Free(*data);
+ free(*data);
*data = decrypt_data;
*length = decrypt_length;
}
}
tlv_data_free(td, td_len);
- TPM_Free(filedata);
+ free(filedata);
TPM_DEBUG(" SWTPM_NVRAM_StoreData: rc=%d\n", rc);
rc = SWTPM_NVRAM_StoreData(buffer, buflen, tpm_number, name);
}
- TPM_Free(buffer);
+ free(buffer);
return rc;
}
return TPM_FAIL;
}
- rc = TPM_Malloc(&buffer, md_len);
+ buffer = malloc(md_len);
- if (rc == TPM_SUCCESS) {
+ if (buffer) {
*td = TLV_DATA(TAG_HMAC, md_len, buffer);
memcpy(buffer, md, md_len);
+ } else {
+ logprintf(STDOUT_FILENO,
+ "Could not allocate %u bytes.\n", md_len);
+ rc = TPM_FAIL;
}
return rc;
}
if (rc == 0) {
- rc = TPM_Malloc(&dest, data_length);
- if (rc == 0) {
+ dest = malloc(data_length);
+ if (dest) {
*out = dest;
*out_length = data_length;
memcpy(dest, data, data_length);
+ } else {
+ logprintf(STDOUT_FILENO,
+ "Could not allocated %u bytes.\n", data_length);
+ rc = TPM_FAIL;
}
}
default:
rc = TPM_FAIL;
}
- TPM_Free(tmp_data);
+ free(tmp_data);
}
}
switch (hdrversion) {
case 1:
- rc = TPM_Malloc(plain, length);
- if (rc == 0) {
+ *plain = malloc(length);
+ if (*plain) {
memcpy(*plain, data, length);
*plain_length = length;
+ } else {
+ logprintf(STDERR_FILENO,
+ "Could not allocate %u bytes.\n", length);
+ rc = TPM_FAIL;
}
break;
rc = TPM_FAIL;
break;
}
- rc = TPM_Malloc(plain, td->tlv.length);
- if (rc == 0) {
+ *plain = malloc(td->tlv.length);
+ if (*plain) {
memcpy(*plain, td->u.const_ptr, td->tlv.length);
*plain_length = td->tlv.length;
+ } else {
+ logprintf(STDERR_FILENO,
+ "Could not allocate %u bytes.\n", td->tlv.length);
+ rc = TPM_FAIL;
}
break;
}
};
TPM_RESULT res;
- res = TPM_Malloc(&out, out_len);
- if (res != TPM_SUCCESS)
+ out = malloc(out_len);
+ if (!out) {
+ logprintf(STDERR_FILENO,
+ "Could not allocate %u bytes.\n", out_len);
+ res = TPM_FAIL;
goto error;
+ }
memcpy(out, &bh, sizeof(bh));
memcpy(&out[sizeof(bh)], *data, *length);
- TPM_Free(*data);
+ free(*data);
*data = out;
*length = out_len;
- return res;
+ return TPM_SUCCESS;
error:
- TPM_Free(*data);
+ free(*data);
*data = NULL;
*length = 0;
err_exit:
tlv_data_free(td, td_len);
- TPM_Free(buffer);
- TPM_Free(plain);
+ free(buffer);
+ free(plain);
return res;
}
/* SetState will make a copy of the buffer */
res = TPMLIB_SetState(st, plain, plain_len);
- TPM_Free(plain);
+ free(plain);
cleanup:
- TPM_Free(mig_decrypt);
+ free(mig_decrypt);
return res;
}
#include "config.h"
#include "tlv.h"
+#include "logging.h"
#include <string.h>
#include <libtpms/tpm_library.h>
#include <libtpms/tpm_memory.h>
+#include <libtpms/tpm_error.h>
void
tlv_data_free(tlv_data *td, size_t td_len)
for (i = 0; i < td_len; i++) {
if (!td[i].is_const_ptr)
- TPM_Free(td[i].u.ptr);
+ free(td[i].u.ptr);
memset(&td[i], 0, sizeof(*td));
}
}
tlv_data_append(unsigned char **buffer, uint32_t *buffer_len,
tlv_data *td, size_t td_len)
{
- TPM_RESULT res;
size_t i;
tlv_header tlv;
uint32_t totlen;
size_t addlen = 0;
unsigned char *ptr;
+ unsigned char *tmp;
for (i = 0; i < td_len; i++)
addlen += sizeof(tlv) + td[i].tlv.length;
else
totlen = addlen;
- res = TPM_Realloc(buffer, totlen);
- if (res)
- return res;
+ tmp = realloc(*buffer, totlen);
+ if (!tmp) {
+ logprintf(STDERR_FILENO, "Could not allocate %u bytes.\n", totlen);
+ return TPM_FAIL;
+ }
+ *buffer = tmp;
ptr = *buffer + *buffer_len;
*buffer_len = totlen;
#include <assert.h>
#include <endian.h>
#include <string.h>
+#include <stdlib.h>
#include <libtpms/tpm_library.h>
#include <libtpms/tpm_error.h>
res = be32toh(tpmrh->errcode);
}
*g_locality = orig_locality;
- TPM_Free(rbuffer);
+ free(rbuffer);
return res;
}
if (*rbuffer == NULL ||
*rTotal < sizeof(errresp)) {
- TPM_Realloc(rbuffer, sizeof(errresp));
+ free(*rbuffer);
+
+ *rbuffer = malloc(sizeof(errresp));
if (*rbuffer)
*rTotal = sizeof(errresp);
else