diff options
author | James Bottomley <James.Bottomley@HansenPartnership.com> | 2024-01-02 10:28:27 -0500 |
---|---|---|
committer | James Bottomley <James.Bottomley@HansenPartnership.com> | 2024-01-02 10:37:38 -0500 |
commit | 3d5cdfebb73e291ff2007b4e800101e73dbdb94f (patch) | |
tree | 05636c25051adb8a4488a307ceaa2834aba36845 | |
parent | e7fb66b6a702e31cb24f51ec1e2d4d7187b2462e (diff) | |
download | openssl_tpm2_engine-3d5cdfebb73e291ff2007b4e800101e73dbdb94f.tar.gz |
Fix 32 bit signed conversion
On 32 bits strtol can't be used to convert a hex number with the high
bit set (as happens for persistent handles) because it will overflow
and return LONG_MAX, strtoul must be used instead.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
-rw-r--r-- | src/libcommon/tpm2-common.c | 4 | ||||
-rw-r--r-- | src/tools/create_tpm2_key.c | 4 | ||||
-rw-r--r-- | src/tools/seal_tpm2_data.c | 4 | ||||
-rw-r--r-- | src/tools/signed_tpm2_policy.c | 4 |
4 files changed, 8 insertions, 8 deletions
diff --git a/src/libcommon/tpm2-common.c b/src/libcommon/tpm2-common.c index 2ef8a27..ee1d9d7 100644 --- a/src/libcommon/tpm2-common.c +++ b/src/libcommon/tpm2-common.c @@ -2652,13 +2652,13 @@ static void update_pcrs(TPML_PCR_SELECTION *pcrs, int bank, char *str) if (sep) *sep = '\0'; - from = to = strtol(str, &endptr, 10); + from = to = strtoul(str, &endptr, 10); if (*endptr != '\0' || from < 0 || from >= MAX_TPM_PCRS) goto err; if (sep) { str = sep + 1; - to = strtol(str, &endptr, 10); + to = strtoul(str, &endptr, 10); if (*endptr != '\0' || to < 0 || to >= MAX_TPM_PCRS) goto err; diff --git a/src/tools/create_tpm2_key.c b/src/tools/create_tpm2_key.c index 809b9f9..5baa2ef 100644 --- a/src/tools/create_tpm2_key.c +++ b/src/tools/create_tpm2_key.c @@ -585,10 +585,10 @@ int main(int argc, char **argv) break; case OPT_LOCALITY: has_locality = 1; - locality = strtol(optarg, NULL, 0); + locality = strtoul(optarg, NULL, 0); break; case OPT_SECRET: - secret_handle = strtol(optarg, NULL, 0); + secret_handle = strtoul(optarg, NULL, 0); has_policy = 1; break; default: diff --git a/src/tools/seal_tpm2_data.c b/src/tools/seal_tpm2_data.c index 48d519d..e7eb52a 100644 --- a/src/tools/seal_tpm2_data.c +++ b/src/tools/seal_tpm2_data.c @@ -225,11 +225,11 @@ int main(int argc, char **argv) break; case OPT_LOCALITY: has_locality = 1; - locality = strtol(optarg, NULL, 0); + locality = strtoul(optarg, NULL, 0); break; case OPT_SECRET: has_policy = 1; - secret_handle = strtol(optarg, NULL, 0); + secret_handle = strtoul(optarg, NULL, 0); break; default: printf("Unknown option '%c'\n", c); diff --git a/src/tools/signed_tpm2_policy.c b/src/tools/signed_tpm2_policy.c index 06ea73e..558733f 100644 --- a/src/tools/signed_tpm2_policy.c +++ b/src/tools/signed_tpm2_policy.c @@ -190,10 +190,10 @@ int main(int argc, char **argv) break; case OPT_LOCALITY: has_locality = 1; - locality = strtol(optarg, NULL, 0); + locality = strtoul(optarg, NULL, 0); break; case OPT_SECRET: - secret_handle = strtol(optarg, NULL, 0); + secret_handle = strtoul(optarg, NULL, 0); break; default: printf("Unknown option '%c'\n", c); |