Skip to content

Commit 6ee974b

Browse files
committed
swapped from bigbuf malloc calls to calloc calls on device side. Now all allocations should start from a known state of memory
1 parent b443f63 commit 6ee974b

20 files changed

+58
-54
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
33
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...
44

55
## [unreleased][unreleased]
6+
- Changed from Bigbuf malloc to Bigbuf calloc calls on device side (@iceman1001)
67
- Added `lf t55xx view` - now viewing of T55XX dump files is possible (@iceman1001)
78
- Fixed `lf indala cone` - now writing the right bits when using `--fc` and `--cn`
89
- Changed readline hack logic for async dbg msg to be ready for readline 8.3 (@doegox)

armsrc/BigBuf.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ int emlGet(uint8_t *out, uint32_t offset, uint32_t length) {
354354
tosend_t *get_tosend(void) {
355355

356356
if (s_toSend.buf == NULL) {
357-
s_toSend.buf = BigBuf_malloc(TOSEND_BUFFER_SIZE);
357+
s_toSend.buf = BigBuf_calloc(TOSEND_BUFFER_SIZE);
358358
}
359359
return &s_toSend;
360360
}
@@ -377,8 +377,9 @@ void tosend_stuffbit(int b) {
377377
s_toSend.bit = 0;
378378
}
379379

380-
if (b)
380+
if (b) {
381381
s_toSend.buf[s_toSend.max] |= (1 << (7 - s_toSend.bit));
382+
}
382383

383384
s_toSend.bit++;
384385

@@ -389,15 +390,14 @@ void tosend_stuffbit(int b) {
389390

390391
dmabuf16_t *get_dma16(void) {
391392
if (s_dma_16.buf == NULL) {
392-
s_dma_16.buf = (uint16_t *)BigBuf_malloc(DMA_BUFFER_SIZE * sizeof(uint16_t));
393+
s_dma_16.buf = (uint16_t *)BigBuf_calloc(DMA_BUFFER_SIZE * sizeof(uint16_t));
393394
}
394-
395395
return &s_dma_16;
396396
}
397397

398398
dmabuf8_t *get_dma8(void) {
399-
if (s_dma_8.buf == NULL)
400-
s_dma_8.buf = BigBuf_malloc(DMA_BUFFER_SIZE);
401-
399+
if (s_dma_8.buf == NULL) {
400+
s_dma_8.buf = BigBuf_calloc(DMA_BUFFER_SIZE);
401+
}
402402
return &s_dma_8;
403403
}

armsrc/Standalone/hf_bog.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,18 @@ static void RAMFUNC SniffAndStore(uint8_t param) {
6363
set_tracing(true);
6464

6565
// Array to store the authpwds
66-
uint8_t *capturedPwds = BigBuf_malloc(4 * MAX_PWDS_PER_SESSION);
66+
uint8_t *capturedPwds = BigBuf_calloc(4 * MAX_PWDS_PER_SESSION);
6767

6868
// The command (reader -> tag) that we're receiving.
69-
uint8_t *receivedCmd = BigBuf_malloc(MAX_FRAME_SIZE);
70-
uint8_t *receivedCmdPar = BigBuf_malloc(MAX_PARITY_SIZE);
69+
uint8_t *receivedCmd = BigBuf_calloc(MAX_FRAME_SIZE);
70+
uint8_t *receivedCmdPar = BigBuf_calloc(MAX_PARITY_SIZE);
7171

7272
// The response (tag -> reader) that we're receiving.
73-
uint8_t *receivedResp = BigBuf_malloc(MAX_FRAME_SIZE);
74-
uint8_t *receivedRespPar = BigBuf_malloc(MAX_PARITY_SIZE);
73+
uint8_t *receivedResp = BigBuf_calloc(MAX_FRAME_SIZE);
74+
uint8_t *receivedRespPar = BigBuf_calloc(MAX_PARITY_SIZE);
7575

7676
// The DMA buffer, used to stream samples from the FPGA
77-
uint8_t *dmaBuf = BigBuf_malloc(DMA_BUFFER_SIZE);
77+
uint8_t *dmaBuf = BigBuf_calloc(DMA_BUFFER_SIZE);
7878
uint8_t *data = dmaBuf;
7979

8080
uint8_t previous_data = 0;

armsrc/Standalone/hf_colin.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ static char *ReadSchemasFromSPIFFS(char *filename) {
250250

251251
int changed = rdv40_spiffs_lazy_mount();
252252
uint32_t size = size_in_spiffs((char *)filename);
253-
uint8_t *mem = BigBuf_malloc(size);
253+
uint8_t *mem = BigBuf_calloc(size);
254254
rdv40_spiffs_read_as_filetype((char *)filename, (uint8_t *)mem, size, RDV40_SPIFFS_SAFETY_SAFE);
255255

256256
if (changed) {
@@ -292,7 +292,7 @@ static void ReadLastTagFromFlash(void) {
292292
DbprintfEx(FLAG_NEWLINE, "Button HELD ! Using LAST Known TAG for Simulation...");
293293
cjSetCursLeft();
294294

295-
uint8_t *mem = BigBuf_malloc(size);
295+
uint8_t *mem = BigBuf_calloc(size);
296296

297297
// this one will handle filetype (symlink or not) and resolving by itself
298298
rdv40_spiffs_read_as_filetype((char *)HFCOLIN_LASTTAG_SYMLINK, (uint8_t *)mem, len, RDV40_SPIFFS_SAFETY_SAFE);
@@ -445,11 +445,11 @@ void RunMod(void) {
445445
};
446446

447447
// Can remember something like that in case of Bigbuf
448-
keyBlock = BigBuf_malloc(ARRAYLEN(mfKeys) * 6);
448+
keyBlock = BigBuf_calloc(ARRAYLEN(mfKeys) * MF_KEY_LENGTH);
449449
int mfKeysCnt = ARRAYLEN(mfKeys);
450450

451451
for (int mfKeyCounter = 0; mfKeyCounter < mfKeysCnt; mfKeyCounter++) {
452-
num_to_bytes(mfKeys[mfKeyCounter], 6, (uint8_t *)(keyBlock + mfKeyCounter * 6));
452+
num_to_bytes(mfKeys[mfKeyCounter], MF_KEY_LENGTH, (uint8_t *)(keyBlock + (mfKeyCounter * MF_KEY_LENGTH)));
453453
}
454454

455455
// TODO : remember why we actually had need to initialize this array in such specific case

armsrc/Standalone/hf_iceclass.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ static int reader_attack_mode(void) {
238238

239239
BigBuf_free();
240240
uint16_t mac_response_len = 0;
241-
uint8_t *mac_responses = BigBuf_malloc(MAC_RESPONSES_SIZE);
241+
uint8_t *mac_responses = BigBuf_calloc(MAC_RESPONSES_SIZE);
242242

243243
iclass_simulate(ICLASS_SIM_MODE_READER_ATTACK, NUM_CSNS, false, csns, mac_responses, &mac_response_len);
244244

@@ -250,7 +250,7 @@ static int reader_attack_mode(void) {
250250

251251
size_t dumplen = NUM_CSNS * 24;
252252

253-
uint8_t *dump = BigBuf_malloc(dumplen);
253+
uint8_t *dump = BigBuf_calloc(dumplen);
254254
if (dump == false) {
255255
Dbprintf("Failed to allocate memory");
256256
return PM3_EMALLOC;
@@ -305,6 +305,7 @@ static int reader_dump_mode(void) {
305305
BigBuf_free();
306306

307307
uint8_t *card_data = BigBuf_malloc(ICLASS_16KS_SIZE);
308+
// Don't use calloc since we set allocated memory to 0xFF's
308309
memset(card_data, 0xFF, ICLASS_16KS_SIZE);
309310

310311
if (BUTTON_PRESS()) {
@@ -442,6 +443,7 @@ static int dump_sim_mode(void) {
442443
BigBuf_free();
443444

444445
uint8_t *card_data = BigBuf_malloc(ICLASS_16KS_SIZE);
446+
// Don't use calloc since we set allocated memory to 0xFF's
445447
memset(card_data, 0xFF, ICLASS_16KS_SIZE);
446448

447449
if (BUTTON_PRESS()) {

armsrc/Standalone/hf_mattyrun.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ void RunMod(void) {
247247
// usb_disable();
248248

249249
// Allocate dictionary buffer
250-
uint64_t *const mfcKeys = (uint64_t *)BigBuf_malloc(
250+
uint64_t *const mfcKeys = (uint64_t *)BigBuf_calloc(
251251
sizeof(uint64_t) * (ARRAYLEN(MATTYRUN_MFC_ESSENTIAL_KEYS) +
252252
ARRAYLEN(MATTYRUN_MFC_DEFAULT_KEYS) +
253253
MIFARE_4K_MAXSECTOR * 2));

armsrc/Standalone/lf_icehid.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ static uint32_t IceIOdemod(void) {
199199

200200
size_t size = MIN(12000, BigBuf_max_traceLen());
201201

202-
// uint8_t *dest = BigBuf_malloc(size);
202+
// uint8_t *dest = BigBuf_calloc(size);
203203
uint8_t *dest = BigBuf_get_addr();
204204

205205
//fskdemod and get start index
@@ -243,7 +243,7 @@ static uint32_t IceHIDDemod(void) {
243243
// large enough to catch 2 sequences of largest format
244244
// size_t size = 50 * 128 * 2; // 12800 bytes
245245
size_t size = MIN(12800, BigBuf_max_traceLen());
246-
//uint8_t *dest = BigBuf_malloc(size);
246+
//uint8_t *dest = BigBuf_calloc(size);
247247
uint8_t *dest = BigBuf_get_addr();
248248

249249
// FSK demodulator

armsrc/Standalone/lf_tharexde.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ static bool get_input_data_from_file(uint32_t *tag, char *inputfile) {
103103
if (exists_in_spiffs(inputfile)) {
104104

105105
uint32_t size = size_in_spiffs(inputfile);
106-
uint8_t *mem = BigBuf_malloc(size);
106+
uint8_t *mem = BigBuf_calloc(size);
107107

108-
Dbprintf(_YELLOW_("found input file %s"), inputfile);
108+
Dbprintf("found input file `" _YELLOW_("%s") "`", inputfile);
109109

110110
rdv40_spiffs_read_as_filetype(inputfile, mem, size, RDV40_SPIFFS_SAFETY_SAFE);
111111

armsrc/desfire_crypto.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ void cmac(const desfirekey_t key, uint8_t *ivect, const uint8_t *data, size_t le
334334
return;
335335
}
336336

337-
uint8_t *buffer = BigBuf_malloc(padded_data_length(len, kbs));
337+
uint8_t *buffer = BigBuf_calloc(padded_data_length(len, kbs));
338338

339339
memcpy(buffer, data, len);
340340

armsrc/felica.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ static void iso18092_setup(uint8_t fpga_minor_mode) {
497497
BigBuf_Clear_ext(false);
498498

499499
// Initialize Demod and Uart structs
500-
// DemodInit(BigBuf_malloc(MAX_FRAME_SIZE));
500+
// DemodInit(BigBuf_calloc(MAX_FRAME_SIZE));
501501
FelicaFrameinit(BigBuf_calloc(FELICA_MAX_FRAME_SIZE));
502502

503503
felica_nexttransfertime = 2 * DELAY_ARM2AIR_AS_READER; // 418

0 commit comments

Comments
 (0)