X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/b49aec796c7f1dd7032b879681643dbe465ea72a..7db36608a266a1f0f46dd4032cede2930e221d51:/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; } -