www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/09/06/05:40:18

Date: Sun, 6 Sep 1998 12:37:12 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: OoHOSEoO <oohoseoo AT aol DOT com>
cc: djgpp AT delorie DOT com
Subject: Re: SIGSEGV from reading an executable... (?)
In-Reply-To: <1998090501154700.VAA20831@ladder01.news.aol.com>
Message-ID: <Pine.SUN.3.91.980906123638.20285N-100000@is>
MIME-Version: 1.0

On 5 Sep 1998, OoHOSEoO wrote:

> Exiting due to signal SIGSEGV
> Stack Fault at eip=00001700
> eax=00001c78 ebx=009c4040 ecx=009b7f15 edx=009b7f74 esi=00000054 edi=0000d4c0
> ebp=46464646 esp=009b7f80 program=C:\MYSTUFF\BINARY.EXE

Both the "Stack Fault" and the preposterously messed up value of EBP
suggest that you are trashing the stack.  So you should be looking for
a function that writes past the end of some automatic array.

Here's the villain:

> void convert(int Byte, char* HI, char* LO)
> {
> 	char chr[3];
> 	int status = 0;
> 
> 	sprintf(chr, "%X", Byte);

The declaration of chr[] assumes that Byte will use at most 2
characters to print.  However, since Byte is an int, you cannot rely
on that: the C promotion rules might cause a byte like 0xff be
promoted to an int as 0xffffffff.  In that case, sprintf will
overwrite the stack frame, and KABOOM!

One way to make this problem go away, you need to explicitly mask off
all the bits beyond the low 8:

    sprintf (chr, "%X", Byte & 0xff);

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019