Skip to content

Commit

Permalink
Fix argument parsing in tpm2_policylocality
Browse files Browse the repository at this point in the history
This patch fixes a bug that caused tpm2_policylocality to almost
always generate PolicyLocality(0).

There was a logical inversion that caused almost any argument
(including invalid ones) to be interpreted as zero, except "zero"
would be interpreted as one.

Signed-off-by: Tien-Ren Chen <[email protected]>
  • Loading branch information
trchen1033 authored and idesai committed Dec 7, 2021
1 parent 016a27a commit 7b6600d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tools/tpm2_policylocality.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ static bool on_arg(int argc, char **argv) {
return false;
}

if (strcmp(argv[0], "zero")) {
if (strcmp(argv[0], "zero") == 0) {
ctx.locality = TPMA_LOCALITY_TPM2_LOC_ZERO;
} else if (strcmp(argv[0], "one")) {
} else if (strcmp(argv[0], "one") == 0) {
ctx.locality = TPMA_LOCALITY_TPM2_LOC_ONE;
} else if (strcmp(argv[0], "two")) {
} else if (strcmp(argv[0], "two") == 0) {
ctx.locality = TPMA_LOCALITY_TPM2_LOC_TWO;
} else if (strcmp(argv[0], "three")) {
} else if (strcmp(argv[0], "three") == 0) {
ctx.locality = TPMA_LOCALITY_TPM2_LOC_THREE;
} else if (strcmp(argv[0], "four")) {
} else if (strcmp(argv[0], "four") == 0) {
ctx.locality = TPMA_LOCALITY_TPM2_LOC_FOUR;
} else {
bool result = tpm2_util_string_to_uint8(argv[0], &ctx.locality);
Expand Down

0 comments on commit 7b6600d

Please sign in to comment.