mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 21:33:47 -07:00
chg: converting malloc calls -> calloc which zeros out the allocated memory
This commit is contained in:
parent
989b80007c
commit
939b727c42
9 changed files with 55 additions and 50 deletions
|
@ -382,7 +382,7 @@ int CmdHFFelicaDumpLite(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t tracelen = resp.arg[1];
|
uint64_t tracelen = resp.arg[1];
|
||||||
uint8_t *trace = malloc(tracelen);
|
uint8_t *trace = calloc(tracelen, sizeof(uint8_t));
|
||||||
if ( trace == NULL ) {
|
if ( trace == NULL ) {
|
||||||
PrintAndLogEx(WARNING, "Cannot allocate memory for trace");
|
PrintAndLogEx(WARNING, "Cannot allocate memory for trace");
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -632,7 +632,7 @@ int CmdHFiClassELoad(const char *Cmd) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *dump = malloc(fsize);
|
uint8_t *dump = calloc(fsize, sizeof(uint8_t));
|
||||||
if (!dump) {
|
if (!dump) {
|
||||||
PrintAndLogDevice(WARNING, "error, cannot allocate memory ");
|
PrintAndLogDevice(WARNING, "error, cannot allocate memory ");
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
@ -725,7 +725,12 @@ int CmdHFiClassDecrypt(const char *Cmd) {
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *decrypted = malloc(fsize);
|
uint8_t *decrypted = calloc(fsize, sizeof(uint8_t));
|
||||||
|
if ( !decrypted ) {
|
||||||
|
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
||||||
|
fclose(f);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
size_t bytes_read = fread(decrypted, 1, fsize, f);
|
size_t bytes_read = fread(decrypted, 1, fsize, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
@ -1626,7 +1631,12 @@ int CmdHFiClassReadTagFile(const char *Cmd) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *dump = malloc(fsize);
|
uint8_t *dump = calloc(fsize, sizeof(uint8_t));
|
||||||
|
if ( !dump ) {
|
||||||
|
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
||||||
|
fclose(f);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
size_t bytes_read = fread(dump, 1, fsize, f);
|
size_t bytes_read = fread(dump, 1, fsize, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
|
@ -1783,8 +1793,12 @@ static int loadKeys(char *filename) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *dump = malloc(fsize);
|
uint8_t *dump = calloc(fsize, sizeof(uint8_t));
|
||||||
|
if ( !dump ) {
|
||||||
|
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
||||||
|
fclose(f);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
size_t bytes_read = fread(dump, 1, fsize, f);
|
size_t bytes_read = fread(dump, 1, fsize, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
if (bytes_read > ICLASS_KEYS_MAX * 8){
|
if (bytes_read > ICLASS_KEYS_MAX * 8){
|
||||||
|
|
|
@ -2988,7 +2988,7 @@ int CmdHf14AMfDecryptBytes(const char *Cmd){
|
||||||
PrintAndLogEx(NORMAL, "ar enc\t%08X", ar_enc);
|
PrintAndLogEx(NORMAL, "ar enc\t%08X", ar_enc);
|
||||||
PrintAndLogEx(NORMAL, "at enc\t%08X", at_enc);
|
PrintAndLogEx(NORMAL, "at enc\t%08X", at_enc);
|
||||||
|
|
||||||
uint8_t *data = malloc(len);
|
uint8_t *data = calloc(len, sizeof(uint8_t));
|
||||||
param_gethex_ex(Cmd, 3, data, &len);
|
param_gethex_ex(Cmd, 3, data, &len);
|
||||||
len >>= 1;
|
len >>= 1;
|
||||||
tryDecryptWord( nt, ar_enc, at_enc, data, len);
|
tryDecryptWord( nt, ar_enc, at_enc, data, len);
|
||||||
|
|
|
@ -2002,7 +2002,11 @@ int CmdHF14AMfURestore(const char *Cmd){
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *dump = malloc(fsize);
|
uint8_t *dump = calloc(fsize, sizeof(uint8_t));
|
||||||
|
if ( !dump ) {
|
||||||
|
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// read all data
|
// read all data
|
||||||
size_t bytes_read = fread(dump, 1, fsize, f);
|
size_t bytes_read = fread(dump, 1, fsize, f);
|
||||||
|
|
|
@ -30,7 +30,7 @@ size_t nbytes(size_t nbits) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int CmdLFHitagList(const char *Cmd) {
|
int CmdLFHitagList(const char *Cmd) {
|
||||||
uint8_t *got = malloc(USB_CMD_DATA_SIZE);
|
uint8_t *got = calloc(USB_CMD_DATA_SIZE, sizeof(uint8_t));
|
||||||
if ( !got ) {
|
if ( !got ) {
|
||||||
PrintAndLogEx(WARNING, "Cannot allocate memory for trace");
|
PrintAndLogEx(WARNING, "Cannot allocate memory for trace");
|
||||||
return 2;
|
return 2;
|
||||||
|
|
|
@ -481,7 +481,7 @@ int CmdTraceList(const char *Cmd) {
|
||||||
// reserv some space.
|
// reserv some space.
|
||||||
if (!trace) {
|
if (!trace) {
|
||||||
printf("trace pointer not allocated\n");
|
printf("trace pointer not allocated\n");
|
||||||
trace = malloc(USB_CMD_DATA_SIZE);
|
trace = calloc(USB_CMD_DATA_SIZE, sizeof(uint8_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isOnline ) {
|
if ( isOnline ) {
|
||||||
|
@ -571,8 +571,8 @@ int CmdTraceLoad(const char *Cmd) {
|
||||||
if ( trace )
|
if ( trace )
|
||||||
free(trace);
|
free(trace);
|
||||||
|
|
||||||
trace = malloc(fsize);
|
trace = calloc(fsize, sizeof(uint8_t));
|
||||||
if (trace == NULL) {
|
if (!trace) {
|
||||||
PrintAndLogEx(FAILED, "Cannot allocate memory for trace");
|
PrintAndLogEx(FAILED, "Cannot allocate memory for trace");
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return 2;
|
return 2;
|
||||||
|
|
|
@ -155,17 +155,12 @@ void reverse_arraycopy(uint8_t* arr, uint8_t* dest, size_t len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void printarr(char * name, uint8_t* arr, int len)
|
void printarr(char * name, uint8_t* arr, int len) {
|
||||||
{
|
int cx, i;
|
||||||
int cx;
|
|
||||||
size_t outsize = 40 + strlen(name) + len*5;
|
size_t outsize = 40 + strlen(name) + len*5;
|
||||||
char* output = malloc(outsize);
|
char* output = calloc(outsize, sizeof(char));
|
||||||
memset(output, 0,outsize);
|
|
||||||
|
|
||||||
int i ;
|
|
||||||
cx = snprintf(output,outsize, "uint8_t %s[] = {", name);
|
cx = snprintf(output,outsize, "uint8_t %s[] = {", name);
|
||||||
for(i =0 ; i< len ; i++)
|
for (i=0; i < len; i++) {
|
||||||
{
|
|
||||||
cx += snprintf(output+cx,outsize-cx,"0x%02x,",*(arr+i));//5 bytes per byte
|
cx += snprintf(output+cx,outsize-cx,"0x%02x,",*(arr+i));//5 bytes per byte
|
||||||
}
|
}
|
||||||
cx += snprintf(output+cx,outsize-cx,"};");
|
cx += snprintf(output+cx,outsize-cx,"};");
|
||||||
|
@ -173,17 +168,12 @@ void printarr(char * name, uint8_t* arr, int len)
|
||||||
free(output);
|
free(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
void printvar(char * name, uint8_t* arr, int len)
|
void printvar(char * name, uint8_t* arr, int len) {
|
||||||
{
|
int cx, i;
|
||||||
int cx;
|
|
||||||
size_t outsize = 40 + strlen(name) + len*2;
|
size_t outsize = 40 + strlen(name) + len*2;
|
||||||
char* output = malloc(outsize);
|
char* output = calloc(outsize, sizeof(char));
|
||||||
memset(output, 0,outsize);
|
|
||||||
|
|
||||||
int i ;
|
|
||||||
cx = snprintf(output,outsize,"%s = ", name);
|
cx = snprintf(output,outsize,"%s = ", name);
|
||||||
for(i =0 ; i< len ; i++)
|
for (i=0; i < len; i++) {
|
||||||
{
|
|
||||||
cx += snprintf(output+cx,outsize-cx,"%02x",*(arr+i));//2 bytes per byte
|
cx += snprintf(output+cx,outsize-cx,"%02x",*(arr+i));//2 bytes per byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,18 +181,12 @@ void printvar(char * name, uint8_t* arr, int len)
|
||||||
free(output);
|
free(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
void printarr_human_readable(char * title, uint8_t* arr, int len)
|
void printarr_human_readable(char * title, uint8_t* arr, int len) {
|
||||||
{
|
int cx, i;
|
||||||
int cx;
|
|
||||||
size_t outsize = 100 + strlen(title) + len*4;
|
size_t outsize = 100 + strlen(title) + len*4;
|
||||||
char* output = malloc(outsize);
|
char* output = calloc(outsize, sizeof(char));
|
||||||
memset(output, 0,outsize);
|
|
||||||
|
|
||||||
|
|
||||||
int i;
|
|
||||||
cx = snprintf(output,outsize, "\n\t%s\n", title);
|
cx = snprintf(output,outsize, "\n\t%s\n", title);
|
||||||
for(i =0 ; i< len ; i++)
|
for (i=0; i < len; i++) {
|
||||||
{
|
|
||||||
if (i % 16 == 0)
|
if (i % 16 == 0)
|
||||||
cx += snprintf(output+cx,outsize-cx,"\n%02x| ", i );
|
cx += snprintf(output+cx,outsize-cx,"\n%02x| ", i );
|
||||||
cx += snprintf(output+cx,outsize-cx, "%02x ",*(arr+i));
|
cx += snprintf(output+cx,outsize-cx, "%02x ",*(arr+i));
|
||||||
|
|
|
@ -542,7 +542,11 @@ int bruteforceFile(const char *filename, uint16_t keytable[]) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *dump = malloc(fsize);
|
uint8_t *dump = calloc(fsize, sizeof(uint8_t));
|
||||||
|
if ( !dump ) {
|
||||||
|
PrintAndLogDevice(WARNING, "Failed to allocate memory");
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
size_t bytes_read = fread(dump, 1, fsize, f);
|
size_t bytes_read = fread(dump, 1, fsize, f);
|
||||||
|
|
||||||
if (f) fclose(f);
|
if (f) fclose(f);
|
||||||
|
|
|
@ -71,8 +71,8 @@ static int l_GetFromBigBuf(lua_State *L){
|
||||||
startindex = luaL_checknumber(L, 2);
|
startindex = luaL_checknumber(L, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *data = malloc(len);
|
uint8_t *data = calloc(len, sizeof(uint8_t));
|
||||||
if ( data == NULL ) {
|
if ( !data ) {
|
||||||
//signal error by returning Nil, errorstring
|
//signal error by returning Nil, errorstring
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
lua_pushstring(L,"Allocating memory failed");
|
lua_pushstring(L,"Allocating memory failed");
|
||||||
|
@ -88,7 +88,6 @@ static int l_GetFromBigBuf(lua_State *L){
|
||||||
|
|
||||||
//Push it as a string
|
//Push it as a string
|
||||||
lua_pushlstring(L,(const char *)data, len);
|
lua_pushlstring(L,(const char *)data, len);
|
||||||
if (data)
|
|
||||||
free(data);
|
free(data);
|
||||||
return 1;// return 1 to signal one return value
|
return 1;// return 1 to signal one return value
|
||||||
}
|
}
|
||||||
|
@ -641,7 +640,7 @@ int setLuaPath( lua_State* L, const char* path ) {
|
||||||
lua_getfield( L, -1, "path" ); // get field "path" from table at top of stack (-1)
|
lua_getfield( L, -1, "path" ); // get field "path" from table at top of stack (-1)
|
||||||
const char* cur_path = lua_tostring( L, -1 ); // grab path string from top of stack
|
const char* cur_path = lua_tostring( L, -1 ); // grab path string from top of stack
|
||||||
int requiredLength = strlen(cur_path)+ strlen(path)+10; //A few bytes too many, whatever we can afford it
|
int requiredLength = strlen(cur_path)+ strlen(path)+10; //A few bytes too many, whatever we can afford it
|
||||||
char * buf = malloc(requiredLength);
|
char * buf = calloc(requiredLength, sizeof(char));
|
||||||
snprintf(buf, requiredLength, "%s;%s", cur_path, path);
|
snprintf(buf, requiredLength, "%s;%s", cur_path, path);
|
||||||
lua_pop( L, 1 ); // get rid of the string on the stack we just pushed on line 5
|
lua_pop( L, 1 ); // get rid of the string on the stack we just pushed on line 5
|
||||||
lua_pushstring( L, buf ); // push the new one
|
lua_pushstring( L, buf ); // push the new one
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue