Merge pull request #2720 from henrygab/codeQL_fixes2

CodeQL -- Actual fixes
This commit is contained in:
Iceman authored and GitHub committed 2025-01-15 19:02:17 +01:00
commit 7082302a02
10 files changed
+103 -18

No files matched your search

+11 -2
View File
@@ -3226,13 +3226,22 @@ int CmdHF14ANdefRead(const char *Cmd) {
return PM3_EOVFLOW;
}
for (uint16_t i = offset; i < ndef_size + offset; i += max_rapdu_size) {
uint16_t segment_size = max_rapdu_size < ndef_size + offset - i ? max_rapdu_size : ndef_size + offset - i;
for (size_t i = offset; i < ndef_size + offset; i += max_rapdu_size) {
size_t segment_size = max_rapdu_size < ndef_size + offset - i ? max_rapdu_size : ndef_size + offset - i;
keep_field_on = i < ndef_size + offset - max_rapdu_size;
aREAD_NDEF_n = 0;
param_gethex_to_eol("00b00000", 0, aREAD_NDEF, sizeof(aREAD_NDEF), &aREAD_NDEF_n);
aREAD_NDEF[2] = i >> 8;
aREAD_NDEF[3] = i & 0xFF;
// Segment_size is stuffed into a single-byte field below ... so error out if overflows
if (segment_size > 0xFFu) {
PrintAndLogEx(ERR, "Segment size too large (0x%zx > 0xFF)", segment_size);
DropField();
free(ndef_file);
return PM3_EOVFLOW;
}
aREAD_NDEF[4] = segment_size;
res = ExchangeAPDU14a(aREAD_NDEF, aREAD_NDEF_n + 1, activate_field, keep_field_on, response, sizeof(response), &resplen);
+13 -2
View File
@@ -117,17 +117,28 @@ static char *GenerateFilename(const char *prefix, const char *suffix) {
return fptr;
}
// allocates `items` table entries, storing pointer to `*src`
// Each entry stores two keys (A and B), initialized to six-byte value 0xFFFFFFFFFFFF
// Each entry also stores whether the key was "found", defaults to false (0)
static int initSectorTable(sector_t **src, size_t items) {
// typedef struct {
// uint64_t Key[2];
// uint8_t foundKey[2];
// } sector_t;
// This allocates based on the size of a single item
(*src) = calloc(items, sizeof(sector_t));
if (*src == NULL)
if (*src == NULL) {
return PM3_EMALLOC;
}
// empty e_sector
for (size_t i = 0; i < items; i++) {
for (uint8_t j = 0; j < 2; j++) {
(*src)[i].Key[j] = 0xffffffffffff;
(*src)[i].foundKey[j] = 0;
// (*src)[i].foundKey[j] = 0; // calloc zero's these already
}
}
return PM3_SUCCESS;
+1 -1
View File
@@ -245,7 +245,7 @@ static int ask_em410x_binary_decode(bool verbose, uint32_t *hi, uint64_t *lo, ui
else if (ans == -4)
PrintAndLogEx(DEBUG, "DEBUG: Error - Em410x preamble not found");
else if (ans == -5)
PrintAndLogEx(DEBUG, "DEBUG: Error - Em410x Size not correct: %zu", size);
PrintAndLogEx(DEBUG, "DEBUG: Error - Em410x Size not correct: %zu", *size);
else if (ans == -6)
PrintAndLogEx(DEBUG, "DEBUG: Error - Em410x parity failed");
+10 -2
View File
@@ -30,10 +30,12 @@
static int CmdHelp(const char *Cmd);
static void em4x50_prepare_result(const uint8_t *data, int fwr, int lwr, em4x50_word_t *words) {
// Each record is 4 bytes long ... a single line in the dump output
// Reads each record from `data`, reverses the four bytes, and writes to `words`
static void em4x50_prepare_result(const uint8_t *data, int first_record_inclusive, int last_record_inclusive, em4x50_word_t *words) {
// restructure received result in "em4x50_word_t" structure
for (int i = fwr; i <= lwr; i++) {
for (int i = first_record_inclusive; i <= last_record_inclusive; i++) {
for (int j = 0; j < 4; j++) {
words[i].byte[j] = data[i * 4 + (3 - j)];
}
@@ -779,6 +781,12 @@ static int CmdEM4x50Reader(const char *Cmd) {
// iceman, misuse of return status code.
int now = resp.status;
// prevent massive stack corruption if unexpected results from device.
if (now > EM4X50_NO_WORDS) {
PrintAndLogEx(WARNING, "word count was: %d, limiting to %d", now, EM4X50_NO_WORDS);
now = EM4X50_NO_WORDS;
}
if (now > 0) {
em4x50_word_t words[EM4X50_NO_WORDS];