From 108b532b9ae4c9138ad1a25e9ef437183711a05b Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Wed, 12 Apr 2017 16:58:50 -0400 Subject: Handle race condition while fetching key metadata for display. Fetching a list of keys and all of their metadata isn't an atomic process, nor, probably, should it be, so we need to cope with things like a key being deleted via the RPC interface while we're fetching its metadata for display on the console interface. --- projects/hsm/mgmt-keystore.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/projects/hsm/mgmt-keystore.c b/projects/hsm/mgmt-keystore.c index 230bded..f24f49b 100644 --- a/projects/hsm/mgmt-keystore.c +++ b/projects/hsm/mgmt-keystore.c @@ -208,21 +208,21 @@ static int show_keys(struct cli_def *cli, const char *title) for (int i = 0; i < n; i++) { if ((status = hal_uuid_format(&uuids[i], key_name, sizeof(key_name))) != LIBHAL_OK) { - cli_print(cli, "Could not convert key name: %s", + cli_print(cli, "Could not convert key name, skipping: %s", hal_error_string(status)); - return CLI_ERROR; + continue; } if ((status = hal_rpc_pkey_open(client, session, &pkey, &uuids[i])) != LIBHAL_OK) { - cli_print(cli, "Could not open key %s: %s", + cli_print(cli, "Could not open key %s, skipping: %s", key_name, hal_error_string(status)); - return CLI_ERROR; + continue; } if ((status = hal_rpc_pkey_get_key_type(pkey, &type)) != LIBHAL_OK || (status = hal_rpc_pkey_get_key_curve(pkey, &curve)) != LIBHAL_OK || (status = hal_rpc_pkey_get_key_flags(pkey, &flags)) != LIBHAL_OK) - cli_print(cli, "Could not fetch metadata for key %s: %s", + cli_print(cli, "Could not fetch metadata for key %s, skipping: %s", key_name, hal_error_string(status)); if (status == LIBHAL_OK) @@ -231,7 +231,7 @@ static int show_keys(struct cli_def *cli, const char *title) (void) hal_rpc_pkey_close(pkey); if (status != LIBHAL_OK) - return CLI_ERROR; + continue; const char *type_name = "unknown"; switch (type) { -- cgit v1.2.3