6

I have experienced two kind of error,one is segmentation fault, another is Stack smashing detected. I want to know what different between them and the different reasons caused them.

shengfu zou
  • 560
  • 1
  • 7
  • 16

4 Answers4

9

This is typically Undefined behavior.

  • Segmentation fault is typically when your process is accessing memory location to which it doesn't have permission to access, or that location does not exist.

  • Stack smashing is an alert (generated by gcc for instance) that warns about an access out of bounds, for instance, on the stack. Typically that happens when the stack is written to where it shouldn't, like a local array written to at an index out of bounds.

  • Stack overflow is a kind of "stack smashing" that may also trigger this alert. Stack overflow usually happens when the memory allocated for the stack is not large enough to hold functions local variables, return addresses... Typically happens in recursive functions going too deeply (too much accumulation of return addresses and local data). Or if the local variables take too much space in the stack (like huge arrays).

There is a problem in your code that produces undefined behavior. Maybe you could share it with us so that we can help you.

Check in particular:

  • Out of array bounds accesses
  • NULL pointers
  • The size of local variables too important ; these variables should either be stored in the heap, or be dynamically allocated (malloc() ...).
Déjà vu
  • 28,223
  • 6
  • 72
  • 100
2

Segmentation fault is a fault raised by hardware with memory protection, notifying an operating system (OS) about a memory access violation. Stack smashing is reported when there is overflow of data in your program's call stack. Generally program's call stack is of fixed length.

Cool Goose
  • 870
  • 10
  • 16
2

stack overflow and stack smashing both problems are related to faulty code or value found in the variables. For example when a loop run as that it run over extras index of the array and overwrite the value of another variable of the code then , it become problem to the function prolog and epilog to continue to next function hence the current function become unable to return to calle function because overrun of llop has just overwrite the return address of calle instruction and hence EIP pointing to somewhere it not allowed to fetch instruction .All codes into OS are run in memory protection schems , hence you get stack overrun or stack smashing . Segmentation fault is problems is normal situation when dealing with array and pointer in Linux OS . Try this http://www.drdobbs.com/security/anatomy-of-a-stack-smashing-attack-and-h/240001832

Ganesh K
  • 639
  • 10
  • 18
1

Both are memory access violation. Segmentation fault is more general, means you are accessing something you are not allowed to. stack smashing is more specific, means something wrong in your stack. Actually, stack smashing can cause segmentation fault. you can refer to: https://en.wikipedia.org/wiki/Segmentation_fault or Stack smashing detected

Community
  • 1
  • 1
LKW
  • 180
  • 1
  • 3
  • 13