nfc-mfultralight: better parameters checks

This commit is contained in:
Philippe Teuwen 2017-03-31 23:21:17 +02:00
parent abae2bb17b
commit 560f6a6413

View file

@ -476,9 +476,10 @@ main(int argc, const char *argv[])
bool bUID = false; bool bUID = false;
bool bPWD = false; bool bPWD = false;
bool bPart = false; bool bPart = false;
bool bFilename = false;
FILE *pfDump; FILE *pfDump;
if (argc < 2) { if (argc < 3) {
print_usage(argv); print_usage(argv);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -492,7 +493,7 @@ main(int argc, const char *argv[])
} else if (0 == strcmp(argv[arg], "w")) { } else if (0 == strcmp(argv[arg], "w")) {
iAction = 2; iAction = 2;
} else if (0 == strcmp(argv[arg], "--with-uid")) { } 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"); ERR("Please supply a UID of 4, 7 or 10 bytes long. Ex: a1:b2:c3:d4");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -513,19 +514,25 @@ main(int argc, const char *argv[])
bPart= true; bPart= true;
} else if (0 == strcmp(argv[arg], "--pw")) { } else if (0 == strcmp(argv[arg], "--pw")) {
bPWD= true; 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"); ERR("Please supply a PASSWORD of 8 HEX digits");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} else { } else {
//Skip validation of the filename //Skip validation of the filename
if ((arg != 2) && (arg != 4)) { if (arg != 2) {
ERR("%s is not supported option.", argv[arg]); ERR("%s is not a supported option.", argv[arg]);
print_usage(argv); print_usage(argv);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} else {
bFilename = true;
} }
} }
} }
if (! bFilename) {
ERR("Please supply a Mifare Dump filename");
exit(EXIT_FAILURE);
}
nfc_context *context; nfc_context *context;
nfc_init(&context); nfc_init(&context);