tpm2: Add quote parameter to RuntimeCommandsPrint for optional quoting

Not all callers of RuntimeCommandsPrint will want to have the returned
string use quotation marks at the beginning and end of the string.
Therefore, add a quote parameter to this function that allows to avoid
the quoting. Adapt the single caller to pass a quotation mark.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
Stefan Berger 2026-02-22 21:25:19 -05:00 committed by Stefan Berger
parent c87ad14242
commit 837e618627
3 changed files with 8 additions and 5 deletions

View File

@ -431,14 +431,15 @@ RuntimeCommandPrint(char *buffer,
LIB_EXPORT char *
RuntimeCommandsPrint(struct RuntimeCommands *RuntimeCommands,
enum RuntimeCommandType rct)
enum RuntimeCommandType rct,
const char *quote)
{
COMMAND_INDEX commandIndex, commandCodeLo = 0, commandCodeHi = 0;
char *buffer, *nbuffer = NULL;
BOOL first = true, doPrint;
int n;
buffer = strdup("\"");
buffer = strdup(quote);
if (!buffer)
return NULL;
@ -497,7 +498,7 @@ RuntimeCommandsPrint(struct RuntimeCommands *RuntimeCommands,
if (commandCodeLo != 0)
buffer = RuntimeCommandPrint(buffer, first, commandCodeLo, commandCodeHi);
n = asprintf(&nbuffer, "%s\"", buffer);
n = asprintf(&nbuffer, "%s%s", buffer, quote);
free(buffer);
if (n < 0)
return NULL;

View File

@ -57,6 +57,7 @@ enum RuntimeCommandType {
char *
RuntimeCommandsPrint(struct RuntimeCommands *RuntimeCommands,
enum RuntimeCommandType rct);
enum RuntimeCommandType rct,
const char *quote);
#endif /* RUNTIME_COMMANDS_H */

View File

@ -506,7 +506,8 @@ static char *TPM2_GetInfo(enum TPMLIB_InfoFlags flags)
fmt = buffer;
buffer = NULL;
for (rct = RUNTIME_CMD_IMPLEMENTED; rct < RUNTIME_CMD_NUM; rct++) {
runtimeCmds[rct] = RuntimeCommandsPrint(&g_RuntimeProfile.RuntimeCommands, rct);
runtimeCmds[rct] = RuntimeCommandsPrint(&g_RuntimeProfile.RuntimeCommands, rct,
"\"");
if (!runtimeCmds[rct])
goto error;
}