]> cvs.zerfleddert.de Git - proxmark3-svn/commitdiff
FIX: Coverity Scan complains about resourceleaks, array reads outside of index, unini...
authoriceman1001 <iceman@iuse.se>
Wed, 20 Jan 2016 16:13:25 +0000 (17:13 +0100)
committericeman1001 <iceman@iuse.se>
Wed, 20 Jan 2016 16:13:25 +0000 (17:13 +0100)
armsrc/desfire_crypto.c
armsrc/fpgaloader.c
armsrc/iclass.c
armsrc/iso14443a.c
armsrc/iso15693.c
armsrc/mifarecmd.c

index 8bb8034838afb89e82fad9e7378e0dda11c9636f..469a8ec46761a807978d376066269840a586a150 100644 (file)
@@ -84,6 +84,7 @@ void cmac (const desfirekey_t key, uint8_t *ivect, const uint8_t *data, size_t l
     mifare_cypher_blocks_chained (NULL, key, ivect, buffer, len, MCD_SEND, MCO_ENCYPHER);
 
     memcpy (cmac, ivect, kbs);
     mifare_cypher_blocks_chained (NULL, key, ivect, buffer, len, MCD_SEND, MCO_ENCYPHER);
 
     memcpy (cmac, ivect, kbs);
+       free(buffer);
 }
 
 size_t key_block_size (const desfirekey_t key) {
 }
 
 size_t key_block_size (const desfirekey_t key) {
index 7bcee1eb677300c0e1511cdc4c253e92b9497fb7..da85c66c1a424233e875ce63e224008d005b1b56 100644 (file)
@@ -158,9 +158,8 @@ void FpgaSetupSsc(void)
 //-----------------------------------------------------------------------------
 bool FpgaSetupSscDma(uint8_t *buf, int len)
 {
 //-----------------------------------------------------------------------------
 bool FpgaSetupSscDma(uint8_t *buf, int len)
 {
-       if (buf == NULL) {
+       if (buf == NULL)
         return false;
         return false;
-    }
 
        AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS;        // Disable DMA Transfer
        AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) buf;           // transfer to this memory address
 
        AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS;        // Disable DMA Transfer
        AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) buf;           // transfer to this memory address
@@ -184,15 +183,15 @@ static int get_from_fpga_combined_stream(z_streamp compressed_fpga_stream, uint8
                compressed_fpga_stream->avail_out = OUTPUT_BUFFER_LEN;
                fpga_image_ptr = output_buffer;
                int res = inflate(compressed_fpga_stream, Z_SYNC_FLUSH);
                compressed_fpga_stream->avail_out = OUTPUT_BUFFER_LEN;
                fpga_image_ptr = output_buffer;
                int res = inflate(compressed_fpga_stream, Z_SYNC_FLUSH);
-               if (res != Z_OK) {
+
+               if (res != Z_OK)
                        Dbprintf("inflate returned: %d, %s", res, compressed_fpga_stream->msg);
                        Dbprintf("inflate returned: %d, %s", res, compressed_fpga_stream->msg);
-               }
-               if (res < 0) {
+
+               if (res < 0)
                        return res;
                        return res;
-               }
        }
 
        }
 
-       uncompressed_bytes_cnt++;
+       ++uncompressed_bytes_cnt;
        
        return *fpga_image_ptr++;
 }
        
        return *fpga_image_ptr++;
 }
@@ -209,8 +208,7 @@ static int get_from_fpga_stream(int bitstream_version, z_streamp compressed_fpga
                get_from_fpga_combined_stream(compressed_fpga_stream, output_buffer);
        }
 
                get_from_fpga_combined_stream(compressed_fpga_stream, output_buffer);
        }
 
-       return get_from_fpga_combined_stream(compressed_fpga_stream, output_buffer);
-       
+       return get_from_fpga_combined_stream(compressed_fpga_stream, output_buffer);    
 }
 
 
 }
 
 
@@ -247,16 +245,14 @@ static bool reset_fpga_stream(int bitstream_version, z_streamp compressed_fpga_s
 
        fpga_image_ptr = output_buffer;
 
 
        fpga_image_ptr = output_buffer;
 
-       for (uint16_t i = 0; i < FPGA_BITSTREAM_FIXED_HEADER_SIZE; i++) {
+       for (uint16_t i = 0; i < FPGA_BITSTREAM_FIXED_HEADER_SIZE; i++)
                header[i] = get_from_fpga_stream(bitstream_version, compressed_fpga_stream, output_buffer);
                header[i] = get_from_fpga_stream(bitstream_version, compressed_fpga_stream, output_buffer);
-       }
        
        // Check for a valid .bit file (starts with _bitparse_fixed_header)
        
        // Check for a valid .bit file (starts with _bitparse_fixed_header)
-       if(memcmp(_bitparse_fixed_header, header, FPGA_BITSTREAM_FIXED_HEADER_SIZE) == 0) {
+       if(memcmp(_bitparse_fixed_header, header, FPGA_BITSTREAM_FIXED_HEADER_SIZE) == 0)
                return true;
                return true;
-       } else {
-               return false;
-       }
+
+       return false;
 }
 
 
 }
 
 
@@ -413,7 +409,7 @@ static int bitparse_find_section(int bitstream_version, char section_name, unsig
 void FpgaDownloadAndGo(int bitstream_version)
 {
        z_stream compressed_fpga_stream;
 void FpgaDownloadAndGo(int bitstream_version)
 {
        z_stream compressed_fpga_stream;
-       uint8_t output_buffer[OUTPUT_BUFFER_LEN];
+       uint8_t output_buffer[OUTPUT_BUFFER_LEN] = {0x00};
        
        // check whether or not the bitstream is already loaded
        if (downloaded_bitstream == bitstream_version)
        
        // check whether or not the bitstream is already loaded
        if (downloaded_bitstream == bitstream_version)
@@ -447,18 +443,17 @@ void FpgaDownloadAndGo(int bitstream_version)
 void FpgaGatherVersion(int bitstream_version, char *dst, int len)
 {
        unsigned int fpga_info_len;
 void FpgaGatherVersion(int bitstream_version, char *dst, int len)
 {
        unsigned int fpga_info_len;
-       char tempstr[40];
+       char tempstr[40] = {0x00};
        z_stream compressed_fpga_stream;
        z_stream compressed_fpga_stream;
-       uint8_t output_buffer[OUTPUT_BUFFER_LEN];
+       uint8_t output_buffer[OUTPUT_BUFFER_LEN] = {0x00};
        
        dst[0] = '\0';
 
        // ensure that we can allocate enough memory for decompression:
        BigBuf_free();
 
        
        dst[0] = '\0';
 
        // ensure that we can allocate enough memory for decompression:
        BigBuf_free();
 
-       if (!reset_fpga_stream(bitstream_version, &compressed_fpga_stream, output_buffer)) {
+       if (!reset_fpga_stream(bitstream_version, &compressed_fpga_stream, output_buffer))
                return;
                return;
-       }
 
        if(bitparse_find_section(bitstream_version, 'a', &fpga_info_len, &compressed_fpga_stream, output_buffer)) {
                for (uint16_t i = 0; i < fpga_info_len; i++) {
 
        if(bitparse_find_section(bitstream_version, 'a', &fpga_info_len, &compressed_fpga_stream, output_buffer)) {
                for (uint16_t i = 0; i < fpga_info_len; i++) {
index 2dff8a4e7246d4cef8cee4c0ee589ae50c1abd11..7a68ea6bcbb478302cd05a10c2e874293dd6e2c3 100644 (file)
@@ -633,8 +633,6 @@ static RAMFUNC int ManchesterDecoding(int v)
 //-----------------------------------------------------------------------------
 void RAMFUNC SnoopIClass(void)
 {
 //-----------------------------------------------------------------------------
 void RAMFUNC SnoopIClass(void)
 {
-
-
     // We won't start recording the frames that we acquire until we trigger;
     // a good trigger condition to get started is probably when we see a
     // response from the tag.
     // We won't start recording the frames that we acquire until we trigger;
     // a good trigger condition to get started is probably when we see a
     // response from the tag.
@@ -705,22 +703,22 @@ void RAMFUNC SnoopIClass(void)
     for(;;) {
         LED_A_ON();
         WDT_HIT();
     for(;;) {
         LED_A_ON();
         WDT_HIT();
-        int behindBy = (lastRxCounter - AT91C_BASE_PDC_SSC->PDC_RCR) &
-                                (DMA_BUFFER_SIZE-1);
-        if(behindBy > maxBehindBy) {
+        int behindBy = (lastRxCounter - AT91C_BASE_PDC_SSC->PDC_RCR) & (DMA_BUFFER_SIZE-1);
+
+        if ( behindBy > maxBehindBy) {
             maxBehindBy = behindBy;
             maxBehindBy = behindBy;
-            if(behindBy > (9 * DMA_BUFFER_SIZE / 10)) {
+            if ( behindBy > (9 * DMA_BUFFER_SIZE / 10)) {
                 Dbprintf("blew circular buffer! behindBy=0x%x", behindBy);
                 goto done;
             }
         }
                 Dbprintf("blew circular buffer! behindBy=0x%x", behindBy);
                 goto done;
             }
         }
-        if(behindBy < 1) continue;
+        if( behindBy < 1) continue;
 
 
-       LED_A_OFF();
+               LED_A_OFF();
         smpl = upTo[0];
         upTo++;
         lastRxCounter -= 1;
         smpl = upTo[0];
         upTo++;
         lastRxCounter -= 1;
-        if(upTo - dmaBuf > DMA_BUFFER_SIZE) {
+        if (upTo - dmaBuf > DMA_BUFFER_SIZE) {
             upTo -= DMA_BUFFER_SIZE;
             lastRxCounter += DMA_BUFFER_SIZE;
             AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) upTo;
             upTo -= DMA_BUFFER_SIZE;
             lastRxCounter += DMA_BUFFER_SIZE;
             AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) upTo;
@@ -728,77 +726,75 @@ void RAMFUNC SnoopIClass(void)
         }
 
         //samples += 4;
         }
 
         //samples += 4;
-       samples += 1;
+               samples += 1;
 
 
-       if(smpl & 0xF) {
-               decbyte ^= (1 << (3 - div));
-       }
+               if(smpl & 0xF)
+                       decbyte ^= (1 << (3 - div));
+       
        
        
-       // FOR READER SIDE COMMUMICATION...
+               // FOR READER SIDE COMMUMICATION...
 
 
-       decbyter <<= 2;
-       decbyter ^= (smpl & 0x30);
+               decbyter <<= 2;
+               decbyter ^= (smpl & 0x30);
 
 
-       div++;
+               ++div;
        
        
-       if((div + 1) % 2 == 0) {
-               smpl = decbyter;        
-               if(OutOfNDecoding((smpl & 0xF0) >> 4)) {
-                   rsamples = samples - Uart.samples;
-                       time_stop = (GetCountSspClk()-time_0) << 4;
-                   LED_C_ON();
-
-                       //if(!LogTrace(Uart.output,Uart.byteCnt, rsamples, Uart.parityBits,TRUE)) break;
-                       //if(!LogTrace(NULL, 0, Uart.endTime*16 - DELAY_READER_AIR2ARM_AS_SNIFFER, 0, TRUE)) break;
-                       if(tracing)     {
-                               uint8_t parity[MAX_PARITY_SIZE];
-                               GetParity(Uart.output, Uart.byteCnt, parity);
-                               LogTrace(Uart.output,Uart.byteCnt, time_start, time_stop, parity, TRUE);
-                       }
-
+               if (( div + 1) % 2 == 0) {
+                       smpl = decbyter;        
+                       if ( OutOfNDecoding((smpl & 0xF0) >> 4)) {
+                               rsamples = samples - Uart.samples;
+                               time_stop = (GetCountSspClk()-time_0) << 4;
+                               LED_C_ON();
+
+                               //if(!LogTrace(Uart.output,Uart.byteCnt, rsamples, Uart.parityBits,TRUE)) break;
+                               //if(!LogTrace(NULL, 0, Uart.endTime*16 - DELAY_READER_AIR2ARM_AS_SNIFFER, 0, TRUE)) break;
+                               if(tracing)     {
+                                       uint8_t parity[MAX_PARITY_SIZE];
+                                       GetParity(Uart.output, Uart.byteCnt, parity);
+                                       LogTrace(Uart.output,Uart.byteCnt, time_start, time_stop, parity, TRUE);
+                               }
 
 
-                       /* And ready to receive another command. */
-                   Uart.state = STATE_UNSYNCD;
-                   /* And also reset the demod code, which might have been */
-                   /* false-triggered by the commands from the reader. */
-                   Demod.state = DEMOD_UNSYNCD;
-                   LED_B_OFF();
-                   Uart.byteCnt = 0;
-               }else{
-                       time_start = (GetCountSspClk()-time_0) << 4;
+                               /* And ready to receive another command. */
+                               Uart.state = STATE_UNSYNCD;
+                               /* And also reset the demod code, which might have been */
+                               /* false-triggered by the commands from the reader. */
+                               Demod.state = DEMOD_UNSYNCD;
+                               LED_B_OFF();
+                               Uart.byteCnt = 0;
+                       } else {
+                               time_start = (GetCountSspClk()-time_0) << 4;
+                       }
+                       decbyter = 0;
                }
                }
-               decbyter = 0;
-       }
 
 
-       if(div > 3) {
-               smpl = decbyte;
-               if(ManchesterDecoding(smpl & 0x0F)) {
-                       time_stop = (GetCountSspClk()-time_0) << 4;
+               if(div > 3) {
+                       smpl = decbyte;
+                       if(ManchesterDecoding(smpl & 0x0F)) {
+                               time_stop = (GetCountSspClk()-time_0) << 4;
 
 
-                   rsamples = samples - Demod.samples;
-                   LED_B_ON();
+                               rsamples = samples - Demod.samples;
+                               LED_B_ON();
 
 
-                       if(tracing)     {
-                               uint8_t parity[MAX_PARITY_SIZE];
-                               GetParity(Demod.output, Demod.len, parity);
-                               LogTrace(Demod.output, Demod.len, time_start, time_stop, parity, FALSE);
-                       }
+                               if(tracing)     {
+                                       uint8_t parity[MAX_PARITY_SIZE];
+                                       GetParity(Demod.output, Demod.len, parity);
+                                       LogTrace(Demod.output, Demod.len, time_start, time_stop, parity, FALSE);
+                               }
 
 
-                   // And ready to receive another response.
-                   memset(&Demod, 0, sizeof(Demod));
-                       Demod.output = tagToReaderResponse;
-                   Demod.state = DEMOD_UNSYNCD;
-                   LED_C_OFF();
-               }else{
-                       time_start = (GetCountSspClk()-time_0) << 4;
+                               // And ready to receive another response.
+                               memset(&Demod, 0, sizeof(Demod));
+                               Demod.output = tagToReaderResponse;
+                               Demod.state = DEMOD_UNSYNCD;
+                               LED_C_OFF();
+                       } else {
+                               time_start = (GetCountSspClk()-time_0) << 4;
+                       }
+                       
+                       div = 0;
+                       decbyte = 0x00;
                }
                }
-               
-               div = 0;
-               decbyte = 0x00;
-       }
-       //}
 
 
-        if(BUTTON_PRESS()) {
+        if (BUTTON_PRESS()) {
             DbpString("cancelled_a");
             goto done;
         }
             DbpString("cancelled_a");
             goto done;
         }
@@ -813,18 +809,14 @@ done:
     AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS;
     Dbprintf("%x %x %x", maxBehindBy, Uart.state, Uart.byteCnt);
        Dbprintf("%x %x %x", Uart.byteCntMax, BigBuf_get_traceLen(), (int)Uart.output[0]);
     AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTDIS;
     Dbprintf("%x %x %x", maxBehindBy, Uart.state, Uart.byteCnt);
        Dbprintf("%x %x %x", Uart.byteCntMax, BigBuf_get_traceLen(), (int)Uart.output[0]);
-    LED_A_OFF();
-    LED_B_OFF();
-    LED_C_OFF();
-    LED_D_OFF();
+       LEDsoff();
        set_tracing(FALSE);     
 }
 
 void rotateCSN(uint8_t* originalCSN, uint8_t* rotatedCSN) {
        int i; 
        set_tracing(FALSE);     
 }
 
 void rotateCSN(uint8_t* originalCSN, uint8_t* rotatedCSN) {
        int i; 
-       for(i = 0; i < 8; i++) {
+       for(i = 0; i < 8; i++)
                rotatedCSN[i] = (originalCSN[i] >> 3) | (originalCSN[(i+1)%8] << 5);
                rotatedCSN[i] = (originalCSN[i] >> 3) | (originalCSN[(i+1)%8] << 5);
-       }
 }
 
 //-----------------------------------------------------------------------------
 }
 
 //-----------------------------------------------------------------------------
@@ -1339,15 +1331,11 @@ int doIClassSimulation( int simulationMode, uint8_t *reader_mac_buf)
                }
        }
 
                }
        }
 
-       //Dbprintf("%x", cmdsRecvd);
-       LED_A_OFF();
-       LED_B_OFF();
-       LED_C_OFF();
-
+       LEDsoff();
+       
        if(buttonPressed)
        if(buttonPressed)
-       {
                DbpString("Button pressed");
                DbpString("Button pressed");
-       }
+       
        return buttonPressed;
 }
 
        return buttonPressed;
 }
 
index 8e1b7b7d692a3339f8c3b245b2b3f3b21e29c55e..bfd7069b4f463801f75221aebcb3ad8eaa4955b6 100644 (file)
@@ -2399,10 +2399,10 @@ void ReaderMifare(bool first_try)
                                                isOK = -4;                      // Card's PRNG runs at an unexpected frequency or resets unexpectedly
                                                break;
                                        } else {                                // continue for a while, just to collect some debug info
                                                isOK = -4;                      // Card's PRNG runs at an unexpected frequency or resets unexpectedly
                                                break;
                                        } else {                                // continue for a while, just to collect some debug info
-                                               debug_info[strategy][debug_info_nr] = nt_distance;
-                                               debug_info_nr++;
+                                               ++debug_info_nr;
+                                               debug_info[strategy][debug_info_nr] = nt_distance;                                              
                                                if (debug_info_nr == NUM_DEBUG_INFOS) {
                                                if (debug_info_nr == NUM_DEBUG_INFOS) {
-                                                       strategy++;
+                                                       ++strategy;
                                                        debug_info_nr = 0;
                                                }
                                                continue;
                                                        debug_info_nr = 0;
                                                }
                                                continue;
@@ -2427,7 +2427,7 @@ void ReaderMifare(bool first_try)
                        }
                        catch_up_cycles /= elapsed_prng_sequences;
                        if (catch_up_cycles == last_catch_up) {
                        }
                        catch_up_cycles /= elapsed_prng_sequences;
                        if (catch_up_cycles == last_catch_up) {
-                               consecutive_resyncs++;
+                               ++consecutive_resyncs;
                        }
                        else {
                                last_catch_up = catch_up_cycles;
                        }
                        else {
                                last_catch_up = catch_up_cycles;
@@ -2488,8 +2488,8 @@ void ReaderMifare(bool first_try)
        
        if (isOK == -4) {
                if (MF_DBGLEVEL >= 3) {
        
        if (isOK == -4) {
                if (MF_DBGLEVEL >= 3) {
-                       for (uint16_t i = 0; i <= MAX_STRATEGY; i++) {
-                               for(uint16_t j = 0; j < NUM_DEBUG_INFOS; j++) {
+                       for (uint16_t i = 0; i <= MAX_STRATEGY; ++i) {
+                               for(uint16_t j = 0; j < NUM_DEBUG_INFOS; ++j) {
                                        Dbprintf("collected debug info[%d][%d] = %d", i, j, debug_info[i][j]);
                                }
                        }
                                        Dbprintf("collected debug info[%d][%d] = %d", i, j, debug_info[i][j]);
                                }
                        }
index 928439aa1bd46e1afd19f204db782aa50059fffd..1750152678da3aba436d41d553e42f7538a7cef8 100644 (file)
@@ -903,10 +903,7 @@ int SendDataTag(uint8_t *send, int sendlen, int init, int speed, uint8_t **recv)
                *recv=answer;
        }
 
                *recv=answer;
        }
 
-       LED_A_OFF();
-       LED_B_OFF();
-       LED_C_OFF();
-       LED_D_OFF();
+       LEDsoff();
        
        return answerLen;
 }
        
        return answerLen;
 }
index 91aa7218544ee6a2d8a23e72b81e164865b967b2..81bbb355b028e497d6ec43ce45c78be030f9ad09 100644 (file)
@@ -608,7 +608,7 @@ void MifareAcquireEncryptedNonces(uint32_t arg0, uint32_t arg1, uint32_t flags,
 {\r
        uint64_t ui64Key = 0;\r
        uint8_t uid[10];\r
 {\r
        uint64_t ui64Key = 0;\r
        uint8_t uid[10];\r
-       uint32_t cuid;\r
+       uint32_t cuid = 0;\r
        uint8_t cascade_levels = 0;\r
        struct Crypto1State mpcs = {0, 0};\r
        struct Crypto1State *pcs;\r
        uint8_t cascade_levels = 0;\r
        struct Crypto1State mpcs = {0, 0};\r
        struct Crypto1State *pcs;\r
@@ -1348,7 +1348,7 @@ void MifareCollectNonces(uint32_t arg0, uint32_t arg1){
 \r
 void Mifare_DES_Auth1(uint8_t arg0, uint8_t *datain){\r
 \r
 \r
 void Mifare_DES_Auth1(uint8_t arg0, uint8_t *datain){\r
 \r
-       byte_t dataout[11] = {0x00};\r
+       byte_t dataout[12] = {0x00};\r
        uint8_t uid[10] = {0x00};\r
        uint32_t cuid = 0x00;\r
     \r
        uint8_t uid[10] = {0x00};\r
        uint32_t cuid = 0x00;\r
     \r
Impressum, Datenschutz