add NULL checks

This commit is contained in:
iceman1001
2026-09-15 08:14:02 +02:00
parent e3429580fd
commit 57f8613b83
4 changed files with 46 additions and 0 deletions
+8
View File
@@ -76,6 +76,14 @@ static void RAMFUNC SniffAndStore(uint8_t param) {
// The DMA buffer, used to stream samples from the FPGA
uint8_t *dmaBuf = BigBuf_calloc(DMA_BUFFER_SIZE);
if (capturedPwds == NULL || receivedCmd == NULL || receivedCmdPar == NULL ||
receivedResp == NULL || receivedRespPar == NULL || dmaBuf == NULL) {
if (g_dbglevel >= DBG_ERROR) DbpString("hf bog: failed to allocate buffers");
BigBuf_free();
return;
}
uint8_t *data = dmaBuf;
uint8_t previous_data = 0;
+26
View File
@@ -252,6 +252,14 @@ static char *ReadSchemasFromSPIFFS(char *filename) {
int changed = rdv40_spiffs_lazy_mount();
uint32_t size = size_in_spiffs((char *)filename);
uint8_t *mem = BigBuf_calloc(size);
if (mem == NULL) {
if (changed) {
rdv40_spiffs_lazy_unmount();
}
SpinOff(0);
return NULL;
}
rdv40_spiffs_read_as_filetype((char *)filename, (uint8_t *)mem, size, RDV40_SPIFFS_SAFETY_SAFE);
if (changed) {
@@ -264,6 +272,11 @@ static char *ReadSchemasFromSPIFFS(char *filename) {
static void __attribute__((noinline)) add_schemas_from_json_in_spiffs(char *filename) {
const char *jsonfile = ReadSchemasFromSPIFFS((char *)filename);
if (jsonfile == NULL) {
DbprintfEx(FLAG_NEWLINE, "[!!] out of memory, schemas NOT loaded");
cjSetCursLeft();
return;
}
int i, len = strlen(jsonfile);
struct json_token t;
@@ -294,6 +307,12 @@ static void __attribute__((noinline)) ReadLastTagFromFlash(void) {
cjSetCursLeft();
uint8_t *mem = BigBuf_calloc(size);
if (mem == NULL) {
DbprintfEx(FLAG_NEWLINE, "[!!] out of memory, last tag NOT recovered");
cjSetCursLeft();
SpinOff(0);
return;
}
// this one will handle filetype (symlink or not) and resolving by itself
rdv40_spiffs_read_as_filetype((char *)HFCOLIN_LASTTAG_SYMLINK, (uint8_t *)mem, len, RDV40_SPIFFS_SAFETY_SAFE);
@@ -457,6 +476,13 @@ void RunMod(void) {
// Can remember something like that in case of Bigbuf
keyBlock = BigBuf_calloc(ARRAYLEN(mfKeys) * MF_KEY_LENGTH);
if (keyBlock == NULL) {
DbprintfEx(FLAG_NEWLINE, "[!!] out of memory, aborting");
cjSetCursLeft();
SpinOff(0);
return;
}
int mfKeysCnt = ARRAYLEN(mfKeys);
for (int mfKeyCounter = 0; mfKeyCounter < mfKeysCnt; mfKeyCounter++) {
+6
View File
@@ -193,6 +193,12 @@ static bool RAMFUNC sniff_wait_for_rnda_reply(tag_t type) {
uint8_t *receivedResp = BigBuf_calloc(MAX_FRAME_SIZE);
uint8_t *receivedRespPar = BigBuf_calloc(MAX_PARITY_SIZE);
if (receivedCmd == NULL || receivedCmdPar == NULL ||
receivedResp == NULL || receivedRespPar == NULL) {
if (g_dbglevel >= DBG_ERROR) DbpString("hf doegox auth0: failed to allocate buffers");
goto out;
}
uint8_t previous_data = 0;
int maxDataLen = 0, dataLen;
bool TagIsActive = false;
+6
View File
@@ -169,6 +169,12 @@ static bool RAMFUNC sniff_wait_for_commit(tag_t type) {
uint8_t *receivedResp = BigBuf_calloc(MAX_FRAME_SIZE);
uint8_t *receivedRespPar = BigBuf_calloc(MAX_PARITY_SIZE);
if (receivedCmd == NULL || receivedCmdPar == NULL ||
receivedResp == NULL || receivedRespPar == NULL) {
if (g_dbglevel >= DBG_ERROR) DbpString("hf doegox commit: failed to allocate buffers");
goto out;
}
uint8_t previous_data = 0;
int maxDataLen = 0, dataLen;
bool TagIsActive = false;