From: marshmellow42 Date: Fri, 8 Jan 2016 23:26:56 +0000 (-0500) Subject: some @iceman1001 s coverty scan fixes X-Git-Tag: v2.3.0~10^2~1 X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/commitdiff_plain/c4c3af7c1604f46e048d127d66cf93c9aced8ebe?hp=-c some @iceman1001 s coverty scan fixes great work! --- c4c3af7c1604f46e048d127d66cf93c9aced8ebe diff --git a/armsrc/BigBuf.c b/armsrc/BigBuf.c index 8f9ee4be..da3b0ce2 100644 --- a/armsrc/BigBuf.c +++ b/armsrc/BigBuf.c @@ -184,7 +184,7 @@ bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_ traceLen += iLen; // parity bytes - if (iLen != 0) { + if (num_paritybytes != 0) { if (parity != NULL) { memcpy(trace + traceLen, parity, num_paritybytes); } else { diff --git a/armsrc/des.c b/armsrc/des.c index a81df9c8..f1aa80da 100644 --- a/armsrc/des.c +++ b/armsrc/des.c @@ -274,7 +274,7 @@ uint32_t des_f(uint32_t r, uint8_t* kr){ uint64_t data; uint8_t *sbp; /* sboxpointer */ permute((uint8_t*)e_permtab, (uint8_t*)&r, (uint8_t*)&data); - for(i=0; i<7; ++i) + for(i=0; i<6; ++i) ((uint8_t*)&data)[i] ^= kr[i]; /* Sbox substitution */ diff --git a/client/cmdhfepa.c b/client/cmdhfepa.c index e9c63f20..f9f69a88 100644 --- a/client/cmdhfepa.c +++ b/client/cmdhfepa.c @@ -58,6 +58,7 @@ int CmdHFEPACollectPACENonces(const char *Cmd) } // print nonce PrintAndLog("Length: %d, Nonce: %s", nonce_length, nonce); + free(nonce); } if (i < n - 1) { sleep(d); diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index 99070e18..6c85e1c1 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -406,7 +406,7 @@ int CmdHFiClassDecrypt(const char *Cmd) { fclose(f); saveFile(outfilename,"bin", decrypted, blocknum*8); - + free(decrypted); return 0; } diff --git a/client/loclass/cipherutils.c b/client/loclass/cipherutils.c index 83b3c9fa..9a8256bb 100644 --- a/client/loclass/cipherutils.c +++ b/client/loclass/cipherutils.c @@ -171,6 +171,7 @@ void printarr(char * name, uint8_t* arr, int len) } cx += snprintf(output+cx,outsize-cx,"};"); prnlog(output); + free(output); } void printvar(char * name, uint8_t* arr, int len) @@ -188,6 +189,7 @@ void printvar(char * name, uint8_t* arr, int len) } prnlog(output); + free(output); } void printarr_human_readable(char * title, uint8_t* arr, int len) diff --git a/client/util.c b/client/util.c index 32c06e91..c4f7d200 100644 --- a/client/util.c +++ b/client/util.c @@ -497,3 +497,13 @@ void xor(unsigned char *dst, unsigned char *src, size_t len) { int32_t le24toh (uint8_t data[3]) { return (data[2] << 16) | (data[1] << 8) | data[0]; } + +// RotateLeft - Ultralight, Desfire, works on byte level +// 00-01-02 >> 01-02-00 +void rol(uint8_t *data, const size_t len){ + uint8_t first = data[0]; + for (size_t i = 0; i < len-1; i++) { + data[i] = data[i+1]; + } + data[len-1] = first; +} diff --git a/client/util.h b/client/util.h index 6f9a1177..5674adcf 100644 --- a/client/util.h +++ b/client/util.h @@ -17,6 +17,9 @@ #include #include "data.h" +#ifndef ROTR +# define ROTR(x,n) (((uintmax_t)(x) >> (n)) | ((uintmax_t)(x) << ((sizeof(x) * 8) - (n)))) +#endif #ifndef MIN # define MIN(a, b) (((a) < (b)) ? (a) : (b)) #endif @@ -68,3 +71,4 @@ void wiegand_add_parity(uint8_t *target, uint8_t *source, uint8_t length); void xor(unsigned char *dst, unsigned char *src, size_t len); int32_t le24toh(uint8_t data[3]); +void rol(uint8_t *data, const size_t len);