From 22d04fc1c828b6f4aefce68fb2889d84960dca8a Mon Sep 17 00:00:00 2001 From: Klas Lindfors Date: Mon, 2 Feb 2015 10:17:45 +0100 Subject: [PATCH] return error properly on hex decode --- lib/ykpiv.c | 2 ++ tool/yubico-piv-tool.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/lib/ykpiv.c b/lib/ykpiv.c index cbf5bd5..bc6ffbb 100644 --- a/lib/ykpiv.c +++ b/lib/ykpiv.c @@ -466,6 +466,8 @@ ykpiv_rc ykpiv_hex_decode(const char *hex_in, size_t in_len, int index = 0; if(ind_ptr) { index = ind_ptr - hex_translate; + } else { + return YKPIV_PARSE_ERROR; } if(first) { *hex_out = index << 4; diff --git a/tool/yubico-piv-tool.c b/tool/yubico-piv-tool.c index 89baaa8..588bf63 100644 --- a/tool/yubico-piv-tool.c +++ b/tool/yubico-piv-tool.c @@ -1201,6 +1201,7 @@ int main(int argc, char *argv[]) { unsigned char key[KEY_LEN]; size_t key_len = sizeof(key); if(ykpiv_hex_decode(args_info.key_arg, strlen(args_info.key_arg), key, &key_len) != YKPIV_OK) { + fprintf(stderr, "Failed decoding key!\n"); return EXIT_FAILURE; } @@ -1245,6 +1246,7 @@ int main(int argc, char *argv[]) { unsigned char new_key[KEY_LEN]; size_t new_key_len = sizeof(new_key); if(ykpiv_hex_decode(args_info.new_key_arg, strlen(args_info.new_key_arg), new_key, &new_key_len) != YKPIV_OK) { + fprintf(stderr, "Failed decoding new key!\n"); ret = EXIT_FAILURE; } else if(ykpiv_set_mgmkey(state, new_key) != YKPIV_OK) { ret = EXIT_FAILURE;