Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exceptions in VC++ 7.1

Status
Not open for further replies.

damonh78

Programmer
Jul 28, 2005
44
IE
Hi,

I have written some code that generates a buffer overflow on the stack in an application I use. Basically I input a large amount of data into a buffer which uses the flawed strcpy function. This is course causes the application to crash, what I am wondering is what are actually causing the below error messages. I have the \GS switch turned on for overflow protection and notification. Are the errors due to this switch being on or is it just that I am probably the stack frame completely. The application crashes when the strcpy command is called. There are loads of errors of the type below that come up in the debug window. I am overflowing with "a"'s so thats where the 0x61616161 comes from.

Any help would be greatly appreciated,

Regards,

John

First-chance exception at 0x61616161 in xercesProj2.exe: 0xC0000005: Access violation reading location 0x61616161.
First-chance exception at 0x61616161 in xercesProj2.exe: 0xC0000005: Access violation reading location 0x61616161.
First-chance exception at 0x61616161 in xercesProj2.exe: 0xC0000005: Access violation reading location 0x61616161.
First-chance exception at 0x7c90eddc in xercesProj2.exe: 0xC0000005: Access violation writing location 0x00030ff8.
Unhandled exception at 0x7c90eddc in xercesProj2.exe: 0xC0000005: Access violation writing location 0x00030ff8.
First-chance exception at 0x7c90eddc in xercesProj2.exe: 0xC0000005: Access violation writing location 0x00030ff8.
 
Better try localize and present here the suspicious code snippet.
 
Here ya go,

Heres the section of code where the application crashes:

char locationBuf[1024];
memset(locationBuf, 0, sizeof locationBuf);
const char *nlsHome = XMLMsgLoader::getNLSHome();

if (nlsHome)
{
strcpy(locationBuf, nlsHome);
strcat(locationBuf, U_FILE_SEP_STRING);
}

It crashes at the strcpy.

It crashes when I initialise NLSHome as a very long string which is much longer then the 1024 bytes that locationBuf can handle.

Hope this helps,

Regards,

John
 
Hey,

sorry have made my initial post misleading. I know how to fix the potential buffer overflows, I am just wondering what the exception messages mean exactly. What is causing them, is it the overwriting of some memory area that shouldnt be written to. I find it wierd that some of the exceptions are for trying to write to memory and some for trying to read from memory.

Regards,

John
 
They are access violations caused simply by overwriting the bounds of your array.The exception isnt writing to the memory, you are, thats what causes an exception to be raised. Thats obviously how your compiler/debugger deals with this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top