X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/11146fc1e1722ad8780d0589fc2f6a66fa198108..905d2975dc57c0bdcddde70cff0d58d57801a579:/client/cliparser/cliparser.c?ds=sidebyside diff --git a/client/cliparser/cliparser.c b/client/cliparser/cliparser.c index 56be2ca6..95422039 100644 --- a/client/cliparser/cliparser.c +++ b/client/cliparser/cliparser.c @@ -153,10 +153,34 @@ void CLIParserFree() { // convertors int CLIParamHexToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int *datalen) { *datalen = 0; + + int ibuf = 0; + uint8_t buf[256] = {0}; + int res = CLIParamStrToBuf(argstr, buf, maxdatalen * 2, &ibuf); // *2 because here HEX + if (res || !ibuf) + return res; + + switch(param_gethex_to_eol((char *)buf, 0, data, maxdatalen, datalen)) { + case 1: + printf("Parameter error: Invalid HEX value.\n"); + return 1; + case 2: + printf("Parameter error: parameter too large.\n"); + return 2; + case 3: + printf("Parameter error: Hex string must have even number of digits.\n"); + return 3; + } + + return 0; +} + +int CLIParamStrToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int *datalen) { + *datalen = 0; if (!argstr->count) return 0; - char buf[256] = {0}; + uint8_t buf[256] = {0}; int ibuf = 0; for (int i = 0; i < argstr->count; i++) { @@ -168,21 +192,14 @@ int CLIParamHexToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int if (!ibuf) return 0; - - switch(param_gethex_to_eol(buf, 0, data, maxdatalen, datalen)) { - case 1: - printf("Parameter error: Invalid HEX value.\n"); - return 1; - case 2: - printf("Parameter error: parameter too large.\n"); + + if (ibuf > maxdatalen) return 2; - case 3: - printf("Parameter error: Hex string must have even number of digits.\n"); - return 3; - } + + memcpy(data, buf, ibuf); + *datalen = ibuf; return 0; } -