From 560f6a6413c9e6ace8d1cf00205c4b34fe3fd85d Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 31 Mar 2017 23:21:17 +0200 Subject: [PATCH] nfc-mfultralight: better parameters checks --- utils/nfc-mfultralight.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/utils/nfc-mfultralight.c b/utils/nfc-mfultralight.c index 146f207..7b73a8d 100644 --- a/utils/nfc-mfultralight.c +++ b/utils/nfc-mfultralight.c @@ -476,9 +476,10 @@ main(int argc, const char *argv[]) bool bUID = false; bool bPWD = false; bool bPart = false; + bool bFilename = false; FILE *pfDump; - if (argc < 2) { + if (argc < 3) { print_usage(argv); exit(EXIT_FAILURE); } @@ -492,7 +493,7 @@ main(int argc, const char *argv[]) } else if (0 == strcmp(argv[arg], "w")) { iAction = 2; } else if (0 == strcmp(argv[arg], "--with-uid")) { - if (argc < 5) { + if (arg+1 == argc) { ERR("Please supply a UID of 4, 7 or 10 bytes long. Ex: a1:b2:c3:d4"); exit(EXIT_FAILURE); } @@ -513,19 +514,25 @@ main(int argc, const char *argv[]) bPart= true; } else if (0 == strcmp(argv[arg], "--pw")) { bPWD= true; - if(strlen(argv[++arg]) != 8 || ! ev1_load_pwd(iPWD, argv[arg])) { + if(arg+1 == argc || strlen(argv[++arg]) != 8 || ! ev1_load_pwd(iPWD, argv[arg])) { ERR("Please supply a PASSWORD of 8 HEX digits"); exit(EXIT_FAILURE); } } else { //Skip validation of the filename - if ((arg != 2) && (arg != 4)) { - ERR("%s is not supported option.", argv[arg]); + if (arg != 2) { + ERR("%s is not a supported option.", argv[arg]); print_usage(argv); exit(EXIT_FAILURE); + } else { + bFilename = true; } } } + if (! bFilename) { + ERR("Please supply a Mifare Dump filename"); + exit(EXIT_FAILURE); + } nfc_context *context; nfc_init(&context);