Skip to content

Commit

Permalink
tctildr: Compile robustly without default tctis
Browse files Browse the repository at this point in the history
tctildr (dl and nodl) will attempt to load some tctis in a certain
order by default. If the project is compiled without said tctis, it
would fail so far.
Fix this and provide a runtime error instead of compile time.

Signed-off-by: Andreas Fuchs <andreas.fuchs@infineon.com>
  • Loading branch information
AndreasFuchsTPM committed Aug 8, 2023
1 parent 1668bb6 commit 253826a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/tss2-tcti/tctildr-dl.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,14 @@ get_info_default(const TSS2_TCTI_INFO **info,
return TSS2_TCTI_RC_IO_ERROR;
#else
size_t i;
if (ARRAY_SIZE(tctis) == 0) {
LOG_ERROR("No default TCTIs configured during compilation");
return TSS2_TCTI_RC_IO_ERROR;
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wtype-limits"
for (i = 0; i < ARRAY_SIZE(tctis); i++) {
#pragma GCC diagnostic pop
name = tctis[i].file;
LOG_DEBUG("name: %s", name);
if (name == NULL) {
Expand Down Expand Up @@ -256,7 +263,14 @@ tctildr_get_default(TSS2_TCTI_CONTEXT ** tcticontext, void **dlhandle)
TSS2_RC r;
size_t i;

if (ARRAY_SIZE(tctis) == 0) {
LOG_ERROR("No default TCTIs configured during compilation");
return TSS2_TCTI_RC_IO_ERROR;
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wtype-limits"
for (i = 0; i < ARRAY_SIZE(tctis); i++) {
#pragma GCC diagnostic pop
LOG_DEBUG("Attempting to connect using standard TCTI: %s",
tctis[i].description);
r = tcti_from_file(tctis[i].file, tctis[i].conf, tcticontext,
Expand Down
14 changes: 14 additions & 0 deletions src/tss2-tcti/tctildr-nodl.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,14 @@ tctildr_get_default(TSS2_TCTI_CONTEXT ** tcticontext, void **dlhandle)
}
*tcticontext = NULL;

if (ARRAY_SIZE(tctis) == 0) {
LOG_ERROR("No default TCTIs configured during compilation");
return TSS2_TCTI_RC_IO_ERROR;
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wtype-limits"
for (size_t i = 0; i < ARRAY_SIZE(tctis); i++) {
#pragma GCC diagnostic pop
LOG_DEBUG("Attempting to connect using standard TCTI: %s",
tctis[i].description);
rc = tcti_from_init (tctis[i].init,
Expand Down Expand Up @@ -168,7 +175,14 @@ tctildr_get_tcti (const char *name,
return tctildr_get_default (tcti, data);
}

if (ARRAY_SIZE(tctis) == 0) {
LOG_ERROR("No default TCTIs configured during compilation");
return TSS2_TCTI_RC_IO_ERROR;
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wtype-limits"
for (size_t i = 0; i < ARRAY_SIZE(tctis); ++i) {
#pragma GCC diagnostic pop
for (size_t j = 0; j < NAME_ARRAY_SIZE; ++j) {
if (strcmp (name, tctis[i].names[j]))
continue;
Expand Down
3 changes: 3 additions & 0 deletions src/tss2-tcti/tctildr.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ static char *strndup(const char* s, size_t n)
#endif
#else
#include <limits.h>
#ifndef PATH_MAX
#define PATH_MAX 256
#endif
#endif
#include <stdlib.h>
#include <string.h>
Expand Down

0 comments on commit 253826a

Please sign in to comment.