diff options
author | Luigi Semenzato <semenzato@chromium.org> | 2013-08-23 16:49:56 -0700 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2013-08-28 15:50:54 +0000 |
commit | 317e1b49449d23148c4233b508d0a1f14696eafc (patch) | |
tree | e7b1cd139b4aaa06d61d2aa30b74c45c2eeaa1f3 /utility | |
parent | acc9846dc79275d7d62dbdd248fac8951441f4db (diff) | |
download | vboot-317e1b49449d23148c4233b508d0a1f14696eafc.tar.gz |
Avoid exit code overflow for tpmc.
In case of a TPM error, tpmc returns the TPM error code, which can
be greater than 255. In that case the error code is truncated.
Some error codes, such as TPM_E_RETRY, end with a zero byte,
resulting in a successful exit code. This is despicable.
BUG=chromium:234357
TEST=tested with exit codes < 255. Too hard to generate the others.
BRANCH=none
Change-Id: I891a5c0659c06aac778449e2a0a935c5f82ccdb8
Reviewed-on: https://chromium-review.googlesource.com/66885
Reviewed-by: Luigi Semenzato <semenzato@chromium.org>
Commit-Queue: Luigi Semenzato <semenzato@chromium.org>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
Diffstat (limited to 'utility')
-rw-r--r-- | utility/tpmc.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/utility/tpmc.c b/utility/tpmc.c index 98004e80..adcbf6ed 100644 --- a/utility/tpmc.c +++ b/utility/tpmc.c @@ -19,7 +19,7 @@ #include "tpm_error_messages.h" #include "tss_constants.h" -#define OTHER_ERROR 255 +#define OTHER_ERROR 255 /* OTHER_ERROR must be the largest uint8_t value. */ typedef struct command_record { const char* name; @@ -61,9 +61,11 @@ int HexStringToUint8(const char* string, uint8_t* value) { /* TPM error check and reporting. Returns 0 if |result| is 0 (TPM_SUCCESS). * Otherwise looks up a TPM error in the error table and prints the error if - * found. + * found. Then returns min(result, OTHER_ERROR) since some error codes, such + * as TPM_E_RETRY, do not fit in a byte. */ -uint32_t ErrorCheck(uint32_t result, const char* cmd) { +uint8_t ErrorCheck(uint32_t result, const char* cmd) { + uint8_t exit_code = result > OTHER_ERROR ? OTHER_ERROR : result; if (result == 0) { return 0; } else { @@ -74,11 +76,11 @@ uint32_t ErrorCheck(uint32_t result, const char* cmd) { if (tpm_error_table[i].code == result) { fprintf(stderr, "%s\n%s\n", tpm_error_table[i].name, tpm_error_table[i].description); - return result; + return exit_code; } } fprintf(stderr, "the TPM error code is unknown to this program\n"); - return result; + return exit_code; } } |