-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, 2024 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! Commented Jul 6, 2024 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, 2024 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. Commented Jul 6, 2024 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.