From cbb78fb24a084d2953c519b9d476cf037d47d396 Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Wed, 2 Aug 2017 20:09:27 +0200 Subject: [PATCH] tpm2_getmanufec: simplify execute_tool() error codes propagation The tool main function that calls execute_tool() doesn't use the returned value, it only takes 0 as a succeeds value an everything else as an error. So lets just return consistently 1 as an error an 0 as a success, instead of returning a combination of -1 and value set in the return_val variable. Signed-off-by: Javier Martinez Canillas --- tools/tpm2_getmanufec.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tools/tpm2_getmanufec.c b/tools/tpm2_getmanufec.c index 0745c8455..e6e1aaa2d 100644 --- a/tools/tpm2_getmanufec.c +++ b/tools/tpm2_getmanufec.c @@ -537,7 +537,7 @@ int execute_tool (int argc, char *argv[], char *envp[], common_opts_t *opts, if (argc > (int)(2 * sizeof(long_options) / sizeof(struct option)) ) { showArgMismatch(argv[0]); - return -1; + return 1 ; } char *ECcertFilePath = NULL; @@ -548,14 +548,14 @@ int execute_tool (int argc, char *argv[], char *envp[], common_opts_t *opts, case 'H': if (!tpm2_util_string_to_uint32(optarg, &persistentHandle)) { LOG_ERR("\nPlease input the handle used to make EK persistent(hex) in correct format.\n"); - return return_val; + return 1; } break; case 'e': if (optarg == NULL || (strlen(optarg) >= sizeof(TPMU_HA)) ) { LOG_ERR("\nPlease input the endorsement password(optional,no more than %d characters).\n", (int)sizeof(TPMU_HA) - 1); - return return_val; + return 1; } endorsePasswd = optarg; break; @@ -563,7 +563,7 @@ int execute_tool (int argc, char *argv[], char *envp[], common_opts_t *opts, case 'o': if (optarg == NULL || (strlen(optarg) >= sizeof(TPMU_HA)) ) { LOG_ERR("\nPlease input the owner password(optional,no more than %d characters).\n", (int)sizeof(TPMU_HA) - 1); - return return_val; + return 1; } ownerPasswd = optarg; break; @@ -571,7 +571,7 @@ int execute_tool (int argc, char *argv[], char *envp[], common_opts_t *opts, case 'P': if (optarg == NULL || (strlen(optarg) >= sizeof(TPMU_HA)) ) { LOG_ERR("\nPlease input the EK password(optional,no more than %d characters).\n", (int)sizeof(TPMU_HA) - 1); - return return_val; + return 1; } ekPasswd = optarg; break; @@ -580,14 +580,14 @@ int execute_tool (int argc, char *argv[], char *envp[], common_opts_t *opts, algorithmType = tpm2_alg_util_from_optarg(optarg); if (algorithmType == TPM_ALG_ERROR) { LOG_ERR("\nPlease input the algorithm type in correct format.\n"); - return return_val; + return 1; } break; case 'f': if (optarg == NULL ) { LOG_ERR("\nPlease input the file used to save the pub ek.\n"); - return return_val; + return 1; } outputFile = optarg; break; @@ -614,7 +614,7 @@ int execute_tool (int argc, char *argv[], char *envp[], common_opts_t *opts, case 'S': if (EKserverAddr) { LOG_ERR("Multiple specifications of -S\n"); - return return_val; + return 1; } EKserverAddr = optarg; LOG_INFO("TPM Manufacturer EK provisioning address -- %s\n", EKserverAddr); @@ -624,7 +624,7 @@ int execute_tool (int argc, char *argv[], char *envp[], common_opts_t *opts, if (!return_val) { LOG_ERR("Could not convert session handle to number, got: \"%s\"", optarg); - return return_val; + return 1; } is_session_based_auth = true; break; @@ -638,7 +638,7 @@ int execute_tool (int argc, char *argv[], char *envp[], common_opts_t *opts, ECcertFile = fopen(ECcertFilePath, "wb"); if (!ECcertFile) { LOG_ERR("Could not open file for writing: \"%s\"", ECcertFilePath); - return -1; + return 1; } } @@ -648,13 +648,13 @@ int execute_tool (int argc, char *argv[], char *envp[], common_opts_t *opts, return_val = 1; goto err; } - else { - if (!OfflineProv) { - return_val = createEKHandle(sapi_context); - } - provisioning_return_val = TPMinitialProvisioning(); + + if (!OfflineProv) { + return_val = createEKHandle(sapi_context); } + provisioning_return_val = TPMinitialProvisioning(); + if (return_val && provisioning_return_val) { goto err; }