468,777 Members | 2,325 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,777 developers. It's quick & easy.

Memory access violations and Managed C++

In the attached code fragment I have a buffer overflow and
a memory access violation. When I run the code .Net fails to
verify the IL because of the buffer overflow and I get an exception
as expected. My question relates to the memory access violation,
specfically, what should happen? My guess is that since the good
ole new operator allocates the memory we get an SEH memory access
violation exception. Given that this can occur in my managed
code fragment, what assurances do I have when running such code?
I had thought that managed code prevented this kind of access
violation.

Thanks for your help, and sorry for the dumb question, I'm a little
late to the party.

// This is the main project file for VC++ application project
// generated using an Application Wizard.

#include "stdafx.h"

#using <mscorlib.dll>
#include <tchar.h>

using namespace System;

// This is the entry point for this application
int _tmain(void)
{
// TODO: Please replace the sample code below with your own.
int* pInt=new int;

// bad boy
pInt[0xA]=0x999;

int Buffer[0xA];
Buffer[0xAA]=0xDDDD;

//String* pTempStr=new String("Hello world");
//Console::WriteLine(pTempStr);
return 0;
}
Nov 16 '05 #1
1 2282
Verifiable managed code does. Your example does not.

Ronald Laeremans
Visual C++ team

"BillyO" <Bi********@cali.com> wrote in message
news:9l********************************@4ax.com...
In the attached code fragment I have a buffer overflow and
a memory access violation. When I run the code .Net fails to
verify the IL because of the buffer overflow and I get an exception
as expected. My question relates to the memory access violation,
specfically, what should happen? My guess is that since the good
ole new operator allocates the memory we get an SEH memory access
violation exception. Given that this can occur in my managed
code fragment, what assurances do I have when running such code?
I had thought that managed code prevented this kind of access
violation.

Thanks for your help, and sorry for the dumb question, I'm a little
late to the party.

// This is the main project file for VC++ application project
// generated using an Application Wizard.

#include "stdafx.h"

#using <mscorlib.dll>
#include <tchar.h>

using namespace System;

// This is the entry point for this application
int _tmain(void)
{
// TODO: Please replace the sample code below with your own.
int* pInt=new int;

// bad boy
pInt[0xA]=0x999;

int Buffer[0xA];
Buffer[0xAA]=0xDDDD;

//String* pTempStr=new String("Hello world");
//Console::WriteLine(pTempStr);
return 0;
}

Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by Justin Lazanowski | last post: by
1 post views Thread by Thomas Albrecht | last post: by
3 posts views Thread by iwdu15 | last post: by
4 posts views Thread by Bit byte | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.