mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-22 06:13:51 -07:00
cppcheck fix - array out of bounds. last item is null reduce 1 from arr len, zero based index reduce -1 to get index....\n also made the compare caseinsensitive
This commit is contained in:
parent
21061d6d55
commit
221a06321b
3 changed files with 19 additions and 13 deletions
|
@ -3830,7 +3830,7 @@ static int CmdHFiClassEncode(const char *Cmd) {
|
||||||
wiegand_message_t packed;
|
wiegand_message_t packed;
|
||||||
memset(&packed, 0, sizeof(wiegand_message_t));
|
memset(&packed, 0, sizeof(wiegand_message_t));
|
||||||
|
|
||||||
int format_idx = HIDFindCardFormat((char *)format);
|
int format_idx = HIDFindCardFormat(format);
|
||||||
if (format_idx == -1) {
|
if (format_idx == -1) {
|
||||||
PrintAndLogEx(WARNING, "Unknown format: " _YELLOW_("%s"), format);
|
PrintAndLogEx(WARNING, "Unknown format: " _YELLOW_("%s"), format);
|
||||||
return PM3_EINVARG;
|
return PM3_EINVARG;
|
||||||
|
|
|
@ -279,7 +279,7 @@ static int CmdHIDSim(const char *Cmd) {
|
||||||
memset(&packed, 0, sizeof(wiegand_message_t));
|
memset(&packed, 0, sizeof(wiegand_message_t));
|
||||||
|
|
||||||
// format validation
|
// format validation
|
||||||
int format_idx = HIDFindCardFormat((char *)format);
|
int format_idx = HIDFindCardFormat(format);
|
||||||
if (format_idx == -1 && raw_len == 0) {
|
if (format_idx == -1 && raw_len == 0) {
|
||||||
PrintAndLogEx(WARNING, "Unknown format: " _YELLOW_("%s"), format);
|
PrintAndLogEx(WARNING, "Unknown format: " _YELLOW_("%s"), format);
|
||||||
return PM3_EINVARG;
|
return PM3_EINVARG;
|
||||||
|
@ -383,7 +383,7 @@ static int CmdHIDClone(const char *Cmd) {
|
||||||
memset(&packed, 0, sizeof(wiegand_message_t));
|
memset(&packed, 0, sizeof(wiegand_message_t));
|
||||||
|
|
||||||
// format validation
|
// format validation
|
||||||
int format_idx = HIDFindCardFormat((char *)format);
|
int format_idx = HIDFindCardFormat(format);
|
||||||
if (format_idx == -1 && raw_len == 0) {
|
if (format_idx == -1 && raw_len == 0) {
|
||||||
PrintAndLogEx(WARNING, "Unknown format: " _YELLOW_("%s"), format);
|
PrintAndLogEx(WARNING, "Unknown format: " _YELLOW_("%s"), format);
|
||||||
return PM3_EINVARG;
|
return PM3_EINVARG;
|
||||||
|
@ -509,7 +509,7 @@ static int CmdHIDBrute(const char *Cmd) {
|
||||||
formatLen = sizeof(format);
|
formatLen = sizeof(format);
|
||||||
CLIGetStrWithReturn(ctx, 2, format, &formatLen);
|
CLIGetStrWithReturn(ctx, 2, format, &formatLen);
|
||||||
|
|
||||||
format_idx = HIDFindCardFormat((char *) format);
|
format_idx = HIDFindCardFormat(format);
|
||||||
if (format_idx == -1) {
|
if (format_idx == -1) {
|
||||||
PrintAndLogEx(WARNING, "Unknown format: " _YELLOW_("%s"), format);
|
PrintAndLogEx(WARNING, "Unknown format: " _YELLOW_("%s"), format);
|
||||||
CLIParserFree(ctx);
|
CLIParserFree(ctx);
|
||||||
|
|
|
@ -1391,7 +1391,7 @@ void HIDListFormats(void) {
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
PrintAndLogEx(INFO, "------------------------------------------------------------");
|
PrintAndLogEx(INFO, "------------------------------------------------------------");
|
||||||
PrintAndLogEx(INFO, "Available card formats: " _YELLOW_("%" PRIu64), ARRAYLEN(FormatTable));
|
PrintAndLogEx(INFO, "Available card formats: " _YELLOW_("%" PRIu64), ARRAYLEN(FormatTable) - 1);
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1402,27 +1402,33 @@ cardformat_t HIDGetCardFormat(int idx) {
|
||||||
|
|
||||||
int HIDFindCardFormat(const char *format) {
|
int HIDFindCardFormat(const char *format) {
|
||||||
|
|
||||||
if (FormatTable[0].Name == NULL)
|
char* s = str_dup(format);
|
||||||
return -1;
|
str_lower(s);
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
while (FormatTable[i].Name) {
|
||||||
|
|
||||||
// str_lower
|
char* a = str_dup(FormatTable[i].Name);
|
||||||
|
str_lower(a);
|
||||||
|
|
||||||
while (FormatTable[i].Name && strcmp(FormatTable[i].Name, format)) {
|
if (strcmp(a, s) == 0) {
|
||||||
|
free(a);
|
||||||
|
free(s);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(a);
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FormatTable[i].Name)
|
free(s);
|
||||||
return i;
|
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HIDPack(int format_idx, wiegand_card_t *card, wiegand_message_t *packed, bool preamble) {
|
bool HIDPack(int format_idx, wiegand_card_t *card, wiegand_message_t *packed, bool preamble) {
|
||||||
memset(packed, 0, sizeof(wiegand_message_t));
|
memset(packed, 0, sizeof(wiegand_message_t));
|
||||||
|
|
||||||
if ((format_idx < 0) || (format_idx >= ARRAYLEN(FormatTable) - 1))
|
if ((format_idx < 0) || (format_idx > ARRAYLEN(FormatTable) - 2))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return FormatTable[format_idx].Pack(card, packed, preamble);
|
return FormatTable[format_idx].Pack(card, packed, preamble);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue