X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/514ddaa2ff936ded76554a2ad97f6fe978c6f86e..3e82f956d834faf9e78d9c3c2fccfb98d8041bcb:/client/cmdhflegic.c diff --git a/client/cmdhflegic.c b/client/cmdhflegic.c index ec870b90..91682581 100644 --- a/client/cmdhflegic.c +++ b/client/cmdhflegic.c @@ -527,8 +527,7 @@ int CmdLegicRfRawWrite(const char *Cmd) { PrintAndLog("# changing the DCF is irreversible #"); PrintAndLog("#####################################"); PrintAndLog("do youe really want to continue? y(es) n(o)"); - scanf(" %c", &answer); - if (answer == 'y' || answer == 'Y') { + if (scanf(" %c", &answer) > 0 && (answer == 'y' || answer == 'Y')) { SendCommand(&c); return 0; } @@ -567,24 +566,40 @@ int CmdLegicRfFill(const char *Cmd) { int CmdLegicCalcCrc8(const char *Cmd){ - uint8_t *data; + uint8_t *data = NULL; uint8_t cmdp = 0, uidcrc = 0, type=0; bool errors = false; int len = 0; + int bg, en; while(param_getchar(Cmd, cmdp) != 0x00) { switch(param_getchar(Cmd, cmdp)) { case 'b': case 'B': - data = malloc(len); + // peek at length of the input string so we can + // figure out how many elements to malloc in "data" + bg=en=0; + param_getptr(Cmd, &bg, &en, cmdp+1); + len = (en - bg + 1); + + // check that user entered even number of characters + // for hex data string + if (len & 1) { + errors = true; + break; + } + + // it's possible for user to accidentally enter "b" parameter + // more than once - we have to clean previous malloc + if (data) free(data); + data = malloc(len >> 1); if ( data == NULL ) { PrintAndLog("Can't allocate memory. exiting"); errors = true; break; - } - param_gethex_ex(Cmd, cmdp+1, data, &len); - // if odd symbols, (hexbyte must be two symbols) - if ( len & 1 ) errors = true; + } + + param_gethex(Cmd, cmdp+1, data, len); len >>= 1; cmdp += 2; @@ -612,7 +627,7 @@ int CmdLegicCalcCrc8(const char *Cmd){ } //Validations if (errors){ - if (data != NULL) free(data); + if (data) free(data); return usage_legic_calccrc8(); } @@ -625,7 +640,7 @@ int CmdLegicCalcCrc8(const char *Cmd){ break; } - if (data != NULL) free(data); + if (data) free(data); return 0; }