fix string handling and styles

This commit is contained in:
iceman1001 committed 2024-11-02 14:50:31 +01:00
1 parent 307012606b
commit 9ddd833cba
10 files changed
+64 -37

No files matched your search

+6 -5
View File
@@ -202,7 +202,7 @@ static int CmdHFFidoRegister(const char *cmd) {
if (cpplain) {
memset(cdata, 0x00, 32);
chlen = sizeof(cdata);
chlen = sizeof(cdata) - 1; // CLIGetStrWithReturn does not guarantee string to be null-terminated
CLIGetStrWithReturn(ctx, 5, cdata, &chlen);
if (chlen > 16) {
PrintAndLogEx(ERR, "ERROR: challenge parameter length in ASCII mode must be less than 16 chars instead of: %d", chlen);
@@ -226,7 +226,7 @@ static int CmdHFFidoRegister(const char *cmd) {
if (applain) {
memset(adata, 0x00, 32);
applen = sizeof(adata);
applen = sizeof(adata) - 1; // CLIGetStrWithReturn does not guarantee string to be null-terminated
CLIGetStrWithReturn(ctx, 6, adata, &applen);
if (applen > 16) {
PrintAndLogEx(ERR, "ERROR: application parameter length in ASCII mode must be less than 16 chars instead of: %d", applen);
@@ -245,8 +245,9 @@ static int CmdHFFidoRegister(const char *cmd) {
return PM3_EINVARG;
}
}
if (applen)
if (applen) {
memmove(&data[32], adata, 32);
}
CLIParserFree(ctx);
@@ -516,7 +517,7 @@ static int CmdHFFidoAuthenticate(const char *cmd) {
if (cpplain) {
memset(hdata, 0x00, 32);
hdatalen = sizeof(hdata);
hdatalen = sizeof(hdata) - 1; // CLIGetStrWithReturn does not guarantee string to be null-terminated
CLIGetStrWithReturn(ctx, 9, hdata, &hdatalen);
if (hdatalen > 16) {
PrintAndLogEx(ERR, "ERROR: challenge parameter length in ASCII mode must be less than 16 chars instead of: %d", hdatalen);
@@ -542,7 +543,7 @@ static int CmdHFFidoAuthenticate(const char *cmd) {
if (applain) {
memset(hdata, 0x00, 32);
hdatalen = sizeof(hdata);
hdatalen = sizeof(hdata) - 1; // CLIGetStrWithReturn does not guarantee string to be null-terminated
CLIGetStrWithReturn(ctx, 10, hdata, &hdatalen);
if (hdatalen > 16) {
PrintAndLogEx(ERR, "ERROR: application parameter length in ASCII mode must be less than 16 chars instead of: %d", hdatalen);
+3 -3
View File
@@ -2005,7 +2005,7 @@ static int CmdHF14ADesSelectApp(const char *Cmd) {
}
uint8_t dfname[32] = {0};
int dfnamelen = 16;
int dfnamelen = 16; // since max length is 16 chars we don't have to test for 32-1 null termination
CLIGetStrWithReturn(ctx, 12, dfname, &dfnamelen);
bool selectmf = arg_get_lit(ctx, 13);
@@ -2614,8 +2614,8 @@ static int CmdHF14ADesCreateApp(const char *Cmd) {
return PM3_EINVARG;
}
uint8_t dfname[250] = {0};
int dfnamelen = 16;
uint8_t dfname[32] = {0};
int dfnamelen = 16; // since max length is 16 chars we don't have to test for 32-1 null termination
CLIGetStrWithReturn(ctx, 14, dfname, &dfnamelen);
if (dfnamelen == 0) { // no text DF Name supplied
+15 -6
View File
@@ -288,10 +288,12 @@ int CmdLFCommandRead(const char *Cmd) {
uint16_t period_1 = arg_get_u32_def(ctx, 4, 0);
uint16_t period_0 = arg_get_u32_def(ctx, 5, 0);
uint32_t samples = arg_get_u32_def(ctx, 6, 0);
bool verbose = arg_get_lit(ctx, 7);
bool keep_field_on = arg_get_lit(ctx, 8);
bool add_crc_ht = arg_get_lit(ctx, 9);
bool cm = arg_get_lit(ctx, 10);
CLIParserFree(ctx);
if (g_session.pm3_present == false) {
@@ -1124,9 +1126,10 @@ int CmdLFfskSim(const char *Cmd) {
uint8_t fchigh = arg_get_u32_def(ctx, 3, 0);
bool separator = arg_get_lit(ctx, 4);
int raw_len = 64;
char raw[64] = {0};
char raw[65] = {0};
int raw_len = sizeof(raw) - 1; // CLIGetStrWithReturn does not guarantee string to be null-terminated
CLIGetStrWithReturn(ctx, 5, (uint8_t *)raw, &raw_len);
bool verbose = arg_get_lit(ctx, 6);
CLIParserFree(ctx);
@@ -1234,9 +1237,10 @@ int CmdLFaskSim(const char *Cmd) {
bool use_ar = arg_get_lit(ctx, 5);
bool separator = arg_get_lit(ctx, 6);
int raw_len = 64;
char raw[64] = {0};
char raw[65] = {0};
int raw_len = sizeof(raw) - 1; // CLIGetStrWithReturn does not guarantee string to be null-terminated
CLIGetStrWithReturn(ctx, 7, (uint8_t *)raw, &raw_len);
bool verbose = arg_get_lit(ctx, 8);
CLIParserFree(ctx);
@@ -1336,17 +1340,22 @@ int CmdLFpskSim(const char *Cmd) {
arg_lit0("v", "verbose", "verbose output"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
bool use_psk1 = arg_get_lit(ctx, 1);
bool use_psk2 = arg_get_lit(ctx, 2);
bool use_psk3 = arg_get_lit(ctx, 3);
bool invert = arg_get_lit(ctx, 4);
uint8_t clk = arg_get_u32_def(ctx, 5, 0);
uint8_t carrier = arg_get_u32_def(ctx, 6, 2);
int raw_len = 64;
char raw[64] = {0};
char raw[65] = {0};
int raw_len = sizeof(raw) - 1; // CLIGetStrWithReturn does not guarantee string to be null-terminated
CLIGetStrWithReturn(ctx, 7, (uint8_t *)raw, &raw_len);
bool verbose = arg_get_lit(ctx, 8);
CLIParserFree(ctx);
if ((use_psk1 + use_psk2 + use_psk3) > 1) {
+1 -1
View File
@@ -364,8 +364,8 @@ static int CmdEM410xDemod(const char *Cmd) {
size_t max_len = arg_get_u32_def(ctx, 3, 0);
bool invert = arg_get_lit(ctx, 4);
bool amplify = arg_get_lit(ctx, 5);
int bin_len = 512;
uint8_t bin[512] = {0};
int bin_len = sizeof(bin) - 1; // CLIGetStrWithReturn does not guarantee string to be null-terminated
CLIGetStrWithReturn(ctx, 6, bin, &bin_len);
CLIParserFree(ctx);
+1 -1
View File
@@ -236,7 +236,7 @@ static int CmdPacClone(const char *Cmd) {
};
CLIExecWithReturn(ctx, Cmd, argtable, false);
uint8_t cnstr[9] = {0};
uint8_t cnstr[10] = {0};
int cnlen = sizeof(cnstr) - 1; // CLIGetStrWithReturn does not guarantee string to be null-terminated
memset(cnstr, 0x00, sizeof(cnstr));
CLIGetStrWithReturn(ctx, 1, cnstr, &cnlen);
+1 -1
View File
@@ -1952,7 +1952,7 @@ static int CmdT55xxDangerousRaw(const char *Cmd) {
ng.bitlen = 0;
memset(ng.data, 0x00, sizeof(ng.data));
uint8_t bin[128] = {0};
uint8_t bin[129] = {0};
int bin_len = sizeof(bin) - 1; // CLIGetStrWithReturn does not guarantee string to be null-terminated
CLIGetStrWithReturn(ctx, 1, bin, &bin_len);
+1 -1
View File
@@ -1259,7 +1259,7 @@ static int CmdPCSC(const char *Cmd) {
strcpy((char *) host, "localhost");
}
uint8_t port[6] = {0};
uint8_t port[7] = {0};
int portLen = sizeof(port) - 1; // CLIGetStrWithReturn does not guarantee string to be null-terminated
CLIGetStrWithReturn(ctx, 2, port, &portLen);
if (portLen == 0) {
+3 -3
View File
@@ -2040,9 +2040,9 @@ static int CmdEMVScan(const char *Cmd) {
uint8_t psenum = (channel == CC_CONTACT) ? 1 : 2;
uint8_t filename[FILE_PATH_SIZE] = {0};
int filenamelen = sizeof(filename) - 1; // CLIGetStrWithReturn does not guarantee string to be null-terminated
CLIGetStrWithReturn(ctx, 12, filename, &filenamelen);
char filename[FILE_PATH_SIZE] = {0};
int fnlen = 0;
CLIParamStrToBuf(arg_get_str(ctx, 12), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen);
CLIParserFree(ctx);