diff options
author | Nicolas Norvez <norvez@chromium.org> | 2019-04-08 13:21:44 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-04-11 01:36:33 -0700 |
commit | ac05e6ab2098d9f01efa08e94809dea6f02a5c93 (patch) | |
tree | aee305747d05290057bd4b17e2b54461cbcda88c /util | |
parent | a98d904327f88372cfa0c920ed558626939bf4e1 (diff) | |
download | chrome-ec-ac05e6ab2098d9f01efa08e94809dea6f02a5c93.tar.gz |
ectool: cleanup cmd_fp_seed()
- check |argc| before accessing argv[1]
- remove redundant variables/assignments
BRANCH=None
BUG=None
TEST=ectool --name=cros_fp fpseed => fails
TEST=ectool --name=cros_fp fpseed aabb => fails (only 4 bytes)
TEST=ectool --name=cros_fp fpseed aabb...aabb => succeeds
Change-Id: I515de53a2ee3b934da2e930e32d0680375488711
Signed-off-by: Nicolas Norvez <norvez@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1558970
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'util')
-rw-r--r-- | util/ectool.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/util/ectool.c b/util/ectool.c index 8c3e971afd..9d51cc7bc4 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -1563,13 +1563,13 @@ int cmd_fp_mode(int argc, char *argv[]) int cmd_fp_seed(int argc, char *argv[]) { struct ec_params_fp_seed p; - const char *seed = argv[1]; - int rv; + char *seed; - if (argc == 1) { - printf("Missing seed argument.\n"); + if (argc != 2) { + fprintf(stderr, "Usage: %s <seed>\n", argv[0]); return 1; } + seed = argv[1]; if (strlen(seed) != FP_CONTEXT_TPM_BYTES) { printf("Invalid seed '%s' is %zd bytes long instead of %d.\n", seed, strlen(seed), FP_CONTEXT_TPM_BYTES); @@ -1579,8 +1579,7 @@ int cmd_fp_seed(int argc, char *argv[]) p.struct_version = FP_TEMPLATE_FORMAT_VERSION; memcpy(p.seed, seed, FP_CONTEXT_TPM_BYTES); - rv = ec_command(EC_CMD_FP_SEED, 0, &p, sizeof(p), NULL, 0); - return rv; + return ec_command(EC_CMD_FP_SEED, 0, &p, sizeof(p), NULL, 0); } int cmd_fp_stats(int argc, char *argv[]) |