-1

My program crashes with the message "*** buffer overflow detected ***: program_name terminated", and I suspect it may be related to the compiler option "_FORTIFY_SOURCE=2" that I use (source: difference between gcc -D_FORTIFY_SOURCE=1 and -D_FORTIFY_SOURCE=2).

In general, how to find the program point that generates such error?

4
  • 1
    Have you used a debugger? Good chance it'll take you directly to the offending line. Commented Jul 6 at 4:16
  • I can try it, my feeling is that it looks to me some extra code added by the compiler makes the program exit normally, not sure if gdb can capture it, but will try, thanks!
    – user180574
    Commented Jul 6 at 4:24
  • Extract a minimal reproducible example and/or use a debugger. Also, read stackoverflow.com/search?q=buffer+overflow+detected. Commented Jul 6 at 5:56
  • 1
    it looks to me some extra code added by the compiler This is like exactly what FORTIFY_SOURCE does, it adds extra code by the compiler that exits under specific conditions.
    – KamilCuk
    Commented Jul 6 at 15:43

1 Answer 1

2

In general, how to find the program point that generates such error?

For this particular error, running the program under debugger will immediately tell you where the error happened.

I can try it, my feeling is that ...

You should try it and your feeling is wrong.

P.S. Building your program with -fsanitize=address (if your compilation and runtime environment supports it) and running it may produce a more informative error message.

Not the answer you're looking for? Browse other questions tagged or ask your own question.