This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Debugging issue with -m32 program



> On Jul 9, 2018, at 3:19 AM, Mahmood Naderan via gdb <gdb@sourceware.org> wrote:
> 
> ...
> Hello,
> I have compiled a simple c program with -m32 option. Thing is that when I want to copy some data into an array, it crashes 
> 
> 
> Breakpoint 1, main (argc=1, argv=0xffffd154) at vuln.c:35
> 35      strcpy( dest, buffer );
> (gdb) p &buffer[0]
> $1 = 0xffffcfb5 '\220' <repeats 50 times>, "\061\300Ph//shh/bin\211\343P\211\342S\211\341\260\v̀", '\220' <repeats 37 times>, "P\336\377\377\377\177"
> (gdb) p &dest[0]
> $2 = 0xffffd02c "\020\334\377", <incomplete sequence \367>
> (gdb) x/100x 0xffffcfb5
> 0xffffcfb5:    0x90909090    0x90909090    0x90909090    0x90909090
> 0xffffcfc5:    0x90909090    0x90909090    0x90909090    0x90909090
> 0xffffcfd5:    0x90909090    0x90909090    0x90909090    0x90909090
> 0xffffcfe5:    0xc0319090    0x2f2f6850    0x2f686873    0x896e6962
> 0xffffcff5:    0xe28950e3    0xb0e18953    0x9080cd0b    0x90909090
> 0xffffd005:    0x90909090    0x90909090    0x90909090    0x90909090
> 0xffffd015:    0x90909090    0x90909090    0x90909090    0x90909090
> 0xffffd025:    0xffffde50    0x10007fff    0x00f7ffdc    0x5cf7ffca
> 0xffffd035:    0xe0ffffd1    0xb7000000    0xe0f7f047    0x90f7ffdd
> 0xffffd045:    0x00ffffd0    0x00000000    0x00000000    0x2c000000
> (gdb) next
> 
> Program received signal SIGSEGV, Segmentation fault.
> 0x56555655 in main (argc=<error reading variable: Cannot access memory at address 0x90909090>, 
>     argv=<error reading variable: Cannot access memory at address 0x90909094>) at vuln.c:37
> 37    }
> 
> 
> 
> 
> Without specifying -m32, there is no problem. I wonder why it tries to access 0x90909090. There is some problem with 32/64 bit data.

If "argc" is not used in "main" -- or at least not from this point onward -- then the compiler can reuse that register for other purposes.  That is probably what is happening here.  Note that this explains the messages in the traceback, but that isn't the reason for the SEGV.  The SEGV is an issue in your program.  Did you overwrite memory by strcpy to an output that's too small?

	paul

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]