osx - VERY strange stack overflow in C++ program -


I wrote a program some time ago (Mac OS X, C ++, SDL, FMOD) and it was not good . But recently I wanted to extend my functionality and added some more code to it and now, when I run it and try to test new functionality, the program crashes with SIGABRT.

On the function stack, I see looking at the debugger:

  • _kill <
  • kill $ UNIX2003
  • Lift
  • __eber
  • __stack_check_file
  • AuditWarz & lt; - My function was revised

As far as I know, "__stack_chk_fail" shows a stack overflow but this is not strange about it. In this function "odtworz", I have some code:

  ... koniec = 0; While (koniec == 0) {... if (mode == 1) {...} else if (mode == 2) {...} else if (mode == 3) {piesniOrkiestrowe [0] = '\ 0'; While (Pissiniorkistova [0] == '\ 0') {Losova Pines (); Char * piesnOrkiestrowa = szukajPiesniOrkiestrowej (); If (piesnOrkiestrowa! = NULL) strcpy (piesniOrkiestrowe, piesnOrkiestrowa); } Characters are now psezapple [25]; Sprintf (hippieplic, "% shirichi /% s", PISNIIIIIIRIIRICT (), pesanye orchestoave); }}  

mode is a global variable and before that the value is set to "2" in the function. And now imagine - if I remove the third statement (mode == 3) which is not executed in this mode, then the program does not crash! Removing the code that does not execute, helps in the situation!

Now, I do not want to delete this code because it is for other modes of my program and it works right there, so where can I find an indication? What could possibly be wrong with this?

This not is a stack overflow error. __stack_chk_fail is called when stack frame corruption is detected. The traditional way to break the stack is a buffer overflow. This code is not in your snippet, it is in dots.


After updating the question with the code with a comment: Both StraPP and Sprintf call stacks are excellent candidates for corruption. In my original reply, the buffer overflow mentioned the problem. Guess: Now piznplic lot looks small Sprintf () The function overwrites "buffer buffer" to "canary" by writing too many characters. When the canary beats on, the runtext will be whistle :)

You can make the array larger, not the actual solution, use the safe option for these tasks, such as snprintf (). I will not mention strncpy ().


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -