TL;DR
A segmentation fault at 0x90909090 usually means your program tried to write data outside the memory it’s allowed to use – a buffer overflow. This guide shows you how to find and fix these errors, focusing on common causes and practical solutions.
Understanding Buffer Overflows
Buffer overflows happen when you copy more data into a fixed-size block of memory (a ‘buffer’) than it can hold. This overwrites other parts of your program’s memory, leading to crashes or even security vulnerabilities. The address 0x90909090 is often seen because it represents NOP instructions, frequently used in exploit development.
Step-by-Step Fix
- Identify the Vulnerable Code: Use a debugger (like GDB) to pinpoint where the crash occurs. Set a breakpoint near the suspected area of memory access.
gdb ./your_programbreak function_nameRun your program with sample input that causes the crash.
- Examine Stack Frames: When the program crashes, use the debugger to inspect the stack frames and registers.
btThis shows you the call stack – which functions were called before the crash. Look for function calls that handle user input or copy data into buffers.
- Check Buffer Sizes: Carefully review the code where data is copied. Make sure the destination buffer is large enough to hold all possible input.
- C/C++: Use functions like
strncpy,snprintf, orfgetsinstead ofstrcpy,sprintf, andgets. These safer alternatives allow you to specify the maximum number of characters to copy.char dest[10]; strncpy(dest, src, sizeof(dest) - 1); dest[sizeof(dest) - 1] = ' '; // Always null-terminate! - Python: Avoid unbounded string concatenation. Use slicing or other methods to control the length of strings.
# Bad: result += user_input # Potential overflow if user_input is too long # Good: result = result[:max_length] + user_input
- C/C++: Use functions like
- Input Validation: Validate all input before copying it into buffers. Check the length, format, and content of the data to ensure it’s within acceptable limits.
if (strlen(user_input) > MAX_INPUT_LENGTH) { // Handle error - don't copy! } - Use Compiler Protections: Enable compiler features that help detect and prevent buffer overflows.
- Stack Canaries: These are random values placed on the stack before function return addresses. If a buffer overflow overwrites the canary, the program detects it.
gcc -fstack-protector your_program.c -o your_program - Address Space Layout Randomization (ASLR): This randomizes the memory addresses of key program components, making it harder for attackers to exploit buffer overflows.
gcc -fPIE -pie your_program.c -o your_program
- Stack Canaries: These are random values placed on the stack before function return addresses. If a buffer overflow overwrites the canary, the program detects it.
- Test Thoroughly: Test your code with a variety of inputs, including very long strings and unexpected characters, to ensure the fix is effective.
- Consider Static Analysis Tools: Use tools like Coverity or SonarQube to automatically scan your code for potential buffer overflows. These can identify issues you might miss during manual review.
Important Notes
- The address 0x90909090 is a common indicator of a buffer overflow, but it doesn’t always mean the problem is in your code. It could be caused by libraries or other external factors.
- Fixing buffer overflows requires careful attention to detail. Always double-check your work and test thoroughly.

