c - Stack around the variable 's' was corrupted -


I found this error in my RC4 algorithm, it works well, but every time this message is too large I get this error, like 1000kB, here's the code:

  char * rc4 (const int * key, int key_size, char * buff, int buff_size) {int i, j , K; Int es [255], RK [255]; // rk = random_key char * encrypted = alloc_char_buffer (buff_size); For (i = 0; i  

'encrypted' to be "non-empty Ended ", so if the string is left 10 I will only assign 10 bytes, 11 for '11 0 'should not be

If you need this, here is the code for alloc_char_buffer (unsigned int)

  char * alloc_char_buffer (unsigned int size) {char * buff = NULL; Buff = (four *) coloc (size + 1, size (four)); If (! Buff) _error ("Program fails to allocate memory."); to return; }   

SWITCH:

  // inversà £ ÃÆ'à ¢ â,¬Å¡Ãƒâ € šÃ, © zero-SWITCH (int * a, Int * b) {* (a) = * (a) ^ * (b); // a random number * (b) = * (a) ^ * (b); // one * (a) = * (a) ^ * (b); // get b}    

  char * encrypted = alloc_char_buffer (buff_size); / * ... * / Encrypted [buff_size] = 10;   

Here is the problem that you assign to buff_size elements. Thus, the last valid index is buff_size-1 , not Buff_size .

Another issue:

  j = (js [ja] + rk [ii])% 256;   

Thus j has the limit of [0, 255], but the is the legal index of only [0, 254]. You either either s as a 256-element array or review algorithm implementation.

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -