Skip to content

Commit

Permalink
tcti:Use heap instead of stack and allocate it as needed when tcti in…
Browse files Browse the repository at this point in the history
…itialize

Signed-off-by: JerryDevis <89641128+JerryDevis@users.noreply.github.com>
  • Loading branch information
JerryDevis authored and William Roberts committed Mar 10, 2022
1 parent da13211 commit 1ec41b4
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/tss2-tcti/tctildr-dl.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ handle_from_name(const char *file,
{
char *file_xfrm = NULL;
size_t size;
size_t len;

if (handle == NULL) {
return TSS2_TCTI_RC_BAD_REFERENCE;
Expand All @@ -92,44 +93,50 @@ handle_from_name(const char *file,
LOG_DEBUG("Could not load TCTI file: \"%s\": %s", file, dlerror());
}

file_xfrm = calloc(PATH_MAX, sizeof(char));
len = snprintf(NULL, 0, TCTI_NAME_TEMPLATE_0, file);
if (len >= PATH_MAX) {
LOG_ERROR("TCTI name truncated in transform.");
return TSS2_TCTI_RC_BAD_VALUE;
}
file_xfrm = calloc(len + 1, sizeof(char));
if (file_xfrm == NULL) {
return TSS2_TCTI_RC_MEMORY;
}
/* 'name' alone didn't work, try libtss2-tcti-<name>.so.0 */
size = snprintf(file_xfrm,
PATH_MAX,
len + 1,
TCTI_NAME_TEMPLATE_0,
file);
if (size >= PATH_MAX) {
if (size >= (len + 1)) {
LOG_ERROR("TCTI name truncated in transform.");
free(file_xfrm);
SAFE_FREE(file_xfrm);
return TSS2_TCTI_RC_BAD_VALUE;
}
*handle = dlopen(file_xfrm, RTLD_NOW);
if (*handle != NULL) {
free(file_xfrm);
SAFE_FREE(file_xfrm);
return TSS2_RC_SUCCESS;
} else {
LOG_DEBUG("Could not load TCTI file \"%s\": %s", file, dlerror());
}
/* libtss2-tcti-<name>.so.0 didn't work, try libtss2-tcti-<name>.so */
size = snprintf(file_xfrm,
PATH_MAX,
len + 1,
TCTI_NAME_TEMPLATE,
file);
if (size >= PATH_MAX) {
if (size >= (len + 1)) {
LOG_ERROR("TCTI name truncated in transform.");
free(file_xfrm);
SAFE_FREE(file_xfrm);
return TSS2_TCTI_RC_BAD_VALUE;
}
*handle = dlopen(file_xfrm, RTLD_NOW);
if (*handle == NULL) {
LOG_DEBUG("Failed to load TCTI for name \"%s\": %s", file, dlerror());
free(file_xfrm);
SAFE_FREE(file_xfrm);
return TSS2_TCTI_RC_NOT_SUPPORTED;
}
free(file_xfrm);

SAFE_FREE(file_xfrm);
return TSS2_RC_SUCCESS;
}
TSS2_RC
Expand Down

0 comments on commit 1ec41b4

Please sign in to comment.