fix, part coverity, part bad user input combo

This commit is contained in:
iceman1001 2020-11-02 17:25:09 +01:00
commit 89e7317489

View file

@ -871,23 +871,35 @@ static int CmdHFiClassELoad(const char *Cmd) {
char filename[FILE_PATH_SIZE] = {0}; char filename[FILE_PATH_SIZE] = {0};
CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen); CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen);
DumpFileType_t dftype = BIN; if (strlen(filename) == 0) {
PrintAndLogEx(ERR, "Error: Please specify a filename");
return PM3_EINVARG;
}
if (arg_get_lit(ctx, 2)) { DumpFileType_t dftype = BIN;
bool use_json = arg_get_lit(ctx, 2);
bool use_eml = arg_get_lit(ctx, 3);
CLIParserFree(ctx);
if (use_json && use_eml) {
PrintAndLogEx(ERR, "Error: can't specify both JSON & EML");
return PM3_EINVARG;
}
if (use_json) {
dftype = JSON; dftype = JSON;
} else if (arg_get_lit(ctx, 3)) { } else if (use_eml) {
dftype = EML; dftype = EML;
} }
CLIParserFree(ctx); size_t bytes_read = 2048;
uint8_t *dump = calloc(2048, sizeof(uint8_t)); uint8_t *dump = calloc(2048, sizeof(uint8_t));
if (!dump) { if (!dump) {
PrintAndLogEx(ERR, "error, cannot allocate memory "); PrintAndLogEx(ERR, "error, cannot allocate memory ");
return PM3_EMALLOC; return PM3_EMALLOC;
} }
size_t bytes_read = 2048;
int res = 0; int res = 0;
switch (dftype) { switch (dftype) {
@ -903,10 +915,10 @@ static int CmdHFiClassELoad(const char *Cmd) {
res = loadFileJSON(filename, dump, 2048, &bytes_read, NULL); res = loadFileJSON(filename, dump, 2048, &bytes_read, NULL);
break; break;
} }
case DICTIONARY: case DICTIONARY: {
PrintAndLogEx(ERR, "No dictionary loaded"); PrintAndLogEx(ERR, "Error: Only BIN/JSON/EML formats allowed");
free(dump); return PM3_EINVARG;
return PM3_ESOFT; }
} }
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {