Skip to content

Commit

Permalink
Fix for 32-bit systems to use strtoul for conversion of hex string …
Browse files Browse the repository at this point in the history
…to unsigned long.
  • Loading branch information
dgarske committed Aug 22, 2024
1 parent a483c9f commit 35fa1fe
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions examples/attestation/certify.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ int TPM2_Certify_Example(void* userCtx, int argc, char *argv[])
}
else if (XSTRNCMP(argv[argc-1], "-certify=", XSTRLEN("-certify=")) == 0) {
const char* certifyStr = argv[argc-1] + XSTRLEN("-certify=");
certifyHandle = (word32)XSTRTOL(certifyStr, NULL, 0);
certifyHandle = (word32)XSTRTOUL(certifyStr, NULL, 0);
}
else if (XSTRNCMP(argv[argc-1], "-signer=", XSTRLEN("-signer=")) == 0) {
const char* signerStr = argv[argc-1] + XSTRLEN("-signer=");
signerHandle = (word32)XSTRTOL(signerStr, NULL, 0);
signerHandle = (word32)XSTRTOUL(signerStr, NULL, 0);
}
else {
printf("Warning: Unrecognized option: %s\n", argv[argc-1]);
Expand Down
2 changes: 1 addition & 1 deletion examples/boot/secure_rot.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ int TPM2_Boot_SecureROT_Example(void* userCtx, int argc, char *argv[])
while (argc > 1) {
if (XSTRNCMP(argv[argc-1], "-nvindex=", XSTRLEN("-nvindex=")) == 0) {
const char* nvIndexStr = argv[argc-1] + XSTRLEN("-nvindex=");
nvIndex = (word32)XSTRTOL(nvIndexStr, NULL, 0);
nvIndex = (word32)XSTRTOUL(nvIndexStr, NULL, 0);
if (!(authHandle == TPM_RH_PLATFORM && (
nvIndex > TPM_20_PLATFORM_MFG_NV_SPACE &&
nvIndex < TPM_20_OWNER_NV_SPACE)) &&
Expand Down
2 changes: 1 addition & 1 deletion examples/keygen/create_primary.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ int TPM2_CreatePrimaryKey_Example(void* userCtx, int argc, char *argv[])
authStr = argv[argc-1] + XSTRLEN("-auth=");
}
else if (XSTRNCMP(argv[argc-1], "-store=", XSTRLEN("-store=")) == 0) {
persistHandle = (word32)XSTRTOL(argv[argc-1] + XSTRLEN("-store="),
persistHandle = (word32)XSTRTOUL(argv[argc-1] + XSTRLEN("-store="),
NULL, 0);
if (persistHandle < 0x81000000 && persistHandle > 0x810FFFF) {
printf("Invalid storage handle %s\n", argv[argc-1] + 7);
Expand Down
2 changes: 1 addition & 1 deletion examples/management/flush.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ int TPM2_Flush_Tool(void* userCtx, int argc, char *argv[])
FlushContext_In flushCtx;

if (argc == 2) {
handle = (word32)XSTRTOL(argv[1], NULL, 0);
handle = (word32)XSTRTOUL(argv[1], NULL, 0);
}
else if (argc == 1) {
allTransientObjects = 1;
Expand Down
2 changes: 1 addition & 1 deletion examples/nvram/counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ int TPM2_NVRAM_Counter_Example(void* userCtx, int argc, char *argv[])
while (argc > 1) {
if (XSTRNCMP(argv[argc-1], "-nvindex=", XSTRLEN("-nvindex=")) == 0) {
const char* nvIndexStr = argv[argc-1] + XSTRLEN("-nvindex=");
nvIndex = (word32)XSTRTOL(nvIndexStr, NULL, 0);
nvIndex = (word32)XSTRTOUL(nvIndexStr, NULL, 0);
if (!(authHandle == TPM_RH_PLATFORM && (
nvIndex > TPM_20_PLATFORM_MFG_NV_SPACE &&
nvIndex < TPM_20_OWNER_NV_SPACE)) &&
Expand Down
2 changes: 1 addition & 1 deletion examples/nvram/policy_nv.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ int TPM2_NVRAM_PolicyNV_Example(void* userCtx, int argc, char *argv[])
while (argc > 1) {
if (XSTRNCMP(argv[argc-1], "-nvindex=", XSTRLEN("-nvindex=")) == 0) {
const char* nvIndexStr = argv[argc-1] + XSTRLEN("-nvindex=");
nvIndex = (word32)XSTRTOL(nvIndexStr, NULL, 0);
nvIndex = (word32)XSTRTOUL(nvIndexStr, NULL, 0);
if (!(authHandle == TPM_RH_PLATFORM && (
nvIndex > TPM_20_PLATFORM_MFG_NV_SPACE &&
nvIndex < TPM_20_OWNER_NV_SPACE)) &&
Expand Down
2 changes: 1 addition & 1 deletion examples/nvram/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ int TPM2_NVRAM_Read_Example(void* userCtx, int argc, char *argv[])
while (argc > 1) {
if (XSTRNCMP(argv[argc-1], "-nvindex=", XSTRLEN("-nvindex=")) == 0) {
const char* nvIndexStr = argv[argc-1] + XSTRLEN("-nvindex=");
nvIndex = (word32)XSTRTOL(nvIndexStr, NULL, 0);
nvIndex = (word32)XSTRTOUL(nvIndexStr, NULL, 0);
if (nvIndex < NV_INDEX_FIRST || nvIndex > NV_INDEX_LAST) {
fprintf(stderr, "Invalid NV Index %s\n", nvIndexStr);
fprintf(stderr, "\tPlatform Range: 0x%x -> 0x%x\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/nvram/store.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ int TPM2_NVRAM_Store_Example(void* userCtx, int argc, char *argv[])
while (argc > 1) {
if (XSTRNCMP(argv[argc-1], "-nvindex=", XSTRLEN("-nvindex=")) == 0) {
const char* nvIndexStr = argv[argc-1] + XSTRLEN("-nvindex=");
nvIndex = (word32)XSTRTOL(nvIndexStr, NULL, 0);
nvIndex = (word32)XSTRTOUL(nvIndexStr, NULL, 0);
if (!(authHandle == TPM_RH_PLATFORM && (
nvIndex > TPM_20_PLATFORM_MFG_NV_SPACE &&
nvIndex < TPM_20_OWNER_NV_SPACE)) &&
Expand Down
3 changes: 1 addition & 2 deletions wolftpm/tpm2_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,8 @@ typedef int64_t INT64;
#ifndef WOLFTPM_CUSTOM_TYPES
#include <stdlib.h>

#define XSTRTOL(s,e,b) strtol((s),(e),(b))
#define XSTRTOUL(s,e,b) strtoul((s),(e),(b))
#define XATOI(s) atoi((s))

#endif

/* make sure file IO macros are available for examples */
Expand Down

0 comments on commit 35fa1fe

Please sign in to comment.