]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmddata.c
FIX: Coverity, out-of-bounds write, CID# 121336, s_index should take factor in consi...
[proxmark3-svn] / client / cmddata.c
index 67e5b810caf2af938ad6267c6b726fd1d8bd453c..270b00e6ec455fa4abb40054ac017cfdfa54f213 100644 (file)
@@ -827,19 +827,20 @@ int CmdUndec(const char *Cmd)
                return 0;
        }
 
-       uint8_t factor = param_get8ex(Cmd, 0,2, 10);
+       uint8_t factor = param_get8ex(Cmd, 0, 2, 10);
        //We have memory, don't we?
        int swap[MAX_GRAPH_TRACE_LEN] = { 0 };
        uint32_t g_index = 0 ,s_index = 0;
-       while(g_index < GraphTraceLen && s_index < MAX_GRAPH_TRACE_LEN)
+       while(g_index < GraphTraceLen && s_index + factor < MAX_GRAPH_TRACE_LEN)
        {
                int count = 0;
-               for(count = 0; count < factor && s_index+count < MAX_GRAPH_TRACE_LEN; count ++)
+               for (count = 0; count < factor && s_index + count < MAX_GRAPH_TRACE_LEN; count++)
                        swap[s_index+count] = GraphBuffer[g_index];
-               s_index+=count;
+               s_index += count;
+               g_index++;
        }
 
-       memcpy(GraphBuffer,swap, s_index * sizeof(int));
+       memcpy(GraphBuffer, swap, s_index * sizeof(int));
        GraphTraceLen = s_index;
        RepaintGraphWindow();
        return 0;
@@ -947,11 +948,10 @@ int FSKrawDemod(const char *Cmd, bool verbose)
 
        //set defaults
        //set options from parameters entered with the command
-       rfLen = param_get8ex(Cmd, 0, 0, 10);
-       invert = param_get8ex(Cmd, 1, 0, 10);
-       fchigh = param_get8ex(Cmd, 2, 0, 10);
-       fclow = param_get8ex(Cmd, 3, 0, 10);
-       
+       rfLen = param_get8(Cmd, 0);
+       invert = param_get8(Cmd, 1);
+       fchigh = param_get8(Cmd, 2);
+       fclow = param_get8(Cmd, 3);
        if (strlen(Cmd)>0 && strlen(Cmd)<=2) {
                 if (rfLen==1){
                        invert = 1;   //if invert option only is used
@@ -963,16 +963,16 @@ int FSKrawDemod(const char *Cmd, bool verbose)
        size_t BitLen = getFromGraphBuf(BitStream);
        if (BitLen==0) return 0;
        //get field clock lengths
-       uint16_t fcs=0;
+       uint8_t fc1=0, fc2=0, rf1=0;
        if (!fchigh || !fclow) {
-               fcs = countFC(BitStream, BitLen, 1);
-               if (!fcs) {
-                       fchigh = 10;
-                       fclow = 8;
-               } else {
-                       fchigh = (fcs >> 8) & 0x00FF;
-                       fclow = fcs & 0x00FF;
+               uint8_t ans = fskClocks(&fc1, &fc2, &rf1, false);
+               if (ans == 0) {
+                       if (g_debugMode) PrintAndLog("\nError: cannot detect valid fsk field clocks");                  
+                       return 0; // can't detect field clock
                }
+               fchigh = fc1;
+               fclow = fc2;
+               if (rfLen == 0) rfLen = rf1;
        }
        //get bit clock length
        if (!rfLen){
@@ -2326,21 +2326,15 @@ int Cmdbin2hex(const char *Cmd)
 }
 
 int usage_data_hex2bin(){
-
-       PrintAndLog("Usage: data bin2hex <binary_digits>");
+       PrintAndLog("Usage: data hex2bin <hex_digits>");
        PrintAndLog("       This function will ignore all non-hexadecimal characters (but stop reading on whitespace)");
        return 0;
-
 }
 
 int Cmdhex2bin(const char *Cmd)
 {
        int bg =0, en =0;
-       if(param_getptr(Cmd, &bg, &en, 0))
-       {
-               return usage_data_hex2bin();
-       }
-
+       if(param_getptr(Cmd, &bg, &en, 0))  return usage_data_hex2bin();
 
        while(bg <= en )
        {
Impressum, Datenschutz