0

Trying to debug a program (with buffer overflows) with a script on python I need to recover all messages a program may send.

On Linux, on terminal a normal call as ./a.out AAA respond with

Your argument is: AAA

with a overflow input: ./a.out AAAAAAA respond with

Your argument is: AAAAAAA

Segmentation fault

I building the python code as follows

import sys, string, os
from subprocess import Popen, PIPE

processName = os.getcwd() + "/a.out"
argument = "AAAAAAAAA"

p = Popen([processName, argument], stdout=PIPE, stderr=PIPE)
output, error = p.communicate()
print(":: %d %s %s" % (p.returncode, output, error))

but I am unable to get the Segmentation fault message

neither found needed parameter as far as I have search

Community
  • 1
  • 1
pGrnd2
  • 514
  • 1
  • 5
  • 14
  • Possible duplicate of https://stackoverflow.com/questions/22250893/capture-segmentation-fault-message-for-a-crashed-subprocess-no-out-and-err-af – mostsquares Feb 22 '19 at 21:28

1 Answers1

0

The process does not actually print Segmentation fault. When you run a.out from the shell, this is actually produced by the shell itself. So, it is not a message produced by your program.

See What actually prints "Segmentation fault"?

But, you can check the return code of your process to see if it was stopped by a segmentation fault by comparing p.returncode to -signal.SIGSEGV from the signal module, see the question linked to below for details.

This question is a possible duplicate of Capture "Segmentation fault" message for a crashed subprocess: no out and err after a call to communicate()

mostsquares
  • 834
  • 8
  • 27