473,387 Members | 3,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

/GS and _set_security_error_handler() not working as expected on VS7.1

I synthetically create an overrun by copying more data than a buffer can
hold:
int buffer[128];
int i = 0;
for (i = 0; i < sizeof(buffer) / sizeof(buffer[0]) + 1; i ++)
{
buffer[i] = i;
}

In debug builds the /RTC option is enabled and catches the overrun.
In release builds the /GS option is enabled, and instead of a security
warning dialog, I get an access violation.

Ultimately I want to use _set_security_handler() to point to my custom
function,
but if I can not get the security dialog to display, I can not test my code.
Any ideas on why the default _security_handler is not called?
Pieter
Nov 16 '05 #1
4 2687
Hi Pieter,

Thank you for using Microsoft MSDN managed newsgroup.

I am sorry if there is any misunderstanding. As I understand, your concern
is the /GS option does not work as expected in VC.NET 2003. I am not sure
about what is the expected behavior you want. Based on my reserch and
experience, I believe that the following article is useful to you. Please
refer to it carefully.

Compiler Security Checks In Depth
http://msdn.microsoft.com/library/de...us/dv_vstechar
t/html/vctchcompilersecuritychecksindepth.asp
"...
This paper discusses buffer overruns and the complete picture of the
Microsoft? Visual C++? .NET security checks feature provided by the /GS
compile-time flag.
..."

There are some examples in the above article. Would you please test them
and tell me how to reproduce your problem step by step in these examples?

If I have misunderstood your conern, please feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #2
On Fri, 17 Oct 2003 15:07:42 -0700, "Pieter" <ms****@insanegenius.com>
wrote:
I synthetically create an overrun by copying more data than a buffer can
hold:
int buffer[128];
int i = 0;
for (i = 0; i < sizeof(buffer) / sizeof(buffer[0]) + 1; i ++)
{
buffer[i] = i;
}

In debug builds the /RTC option is enabled and catches the overrun.
In release builds the /GS option is enabled, and instead of a security
warning dialog, I get an access violation.

Ultimately I want to use _set_security_handler() to point to my custom
function,
but if I can not get the security dialog to display, I can not test my code.
Any ideas on why the default _security_handler is not called?


Interesting. I pasted your code into a default AppWizard skeleton
program and indeed, in a release build I do not get the security
warning. At first I figured it was because you were just overrunning
the buffer by a single integer, but changing the "+ 1" to a "* 2" made
no difference.

However, changing the type of your array from "int" to "char" made the
security warning dialog appear right away. I am guessing that the
compiler only inserts the buffer overrun check code when it sees
character arrays allocated on the stack.

By the way, I do the same thing here - when the security handler
function is called I set the priority of the current thread to time
critical (in an attempt to prevent other threads from confusing the
situation further), then use the imagehlp.dll functions to write a stack
dump for the current thread to a text file. Then we tell the user to
send the stack dump to us. I wouldn't take much more work to extend
this code so that it is similar to Microsoft's "do you want to send this
information back to Microsoft automatically?" facility.

Jon

Nov 16 '05 #3
On Mon, 20 Oct 2003 10:24:02 -0500, Jon Sturgeon
<Jo**@futuresoft.nospam.com> wrote:
However, changing the type of your array from "int" to "char" made the
security warning dialog appear right away. I am guessing that the
compiler only inserts the buffer overrun check code when it sees
character arrays allocated on the stack.


Following-up to my own post here...the article that Jacob Yang posted a
link to in the dotnet.languages.vc newsgroup confirmed my guess. Here
is a quote from the "Performance" section of that article:

"The most important factor behind keeping the performance impact from
being an issue is that only functions that are vulnerable to attack are
targeted. Currently, the definition of a vulnerable function is one that
allocates a type of string buffer on the stack. A string buffer that is
considered vulnerable allocates more than four bytes of storage and
where each element of the buffer is either one or two bytes. Small
buffers are unlikely to be the target of an attack, and limiting the
number of functions that have security checks limits the code growth."

....so the fact that you were allocating an integer buffer means that
your code wasn't a target for the security feature.

Jacob - if you read this you might want to consider checking how you
reply to posts - for some reason your reply didn't make it to the other
newsgroup that the OP posted to.

Jon

Nov 16 '05 #4
Thank you, the vulnerable2() example worked.
"Jacob Yang [MSFT]" <ji***@online.microsoft.com> wrote in message
news:1Z**************@cpmsftngxa06.phx.gbl...
Hi Pieter,

Thank you for using Microsoft MSDN managed newsgroup.

I am sorry if there is any misunderstanding. As I understand, your concern
is the /GS option does not work as expected in VC.NET 2003. I am not sure
about what is the expected behavior you want. Based on my reserch and
experience, I believe that the following article is useful to you. Please
refer to it carefully.

Compiler Security Checks In Depth
http://msdn.microsoft.com/library/de...us/dv_vstechar t/html/vctchcompilersecuritychecksindepth.asp
"...
This paper discusses buffer overruns and the complete picture of the
Microsoft? Visual C++? .NET security checks feature provided by the /GS
compile-time flag.
.."

There are some examples in the above article. Would you please test them
and tell me how to reproduce your problem step by step in these examples?

If I have misunderstood your conern, please feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Jeff | last post by:
ok.... i dont know why this wont work. this is going to access DB on web. var1a = Request.Form("h1") var1b = Request.Form("h2") strSQL = "UPDATE matches SET team1a = " & var1a & ", team1b = "...
1
by: Oz | last post by:
This is long. Bear with me, as I will really go through all the convoluted stuff that shows there is a problem with streams (at least when used to redirect stdout). The basic idea is that my...
3
by: Jason S | last post by:
Hello Group, I am just about tearing my hair out with this one and thought someone may have some insight. I have a transform that wasn't working so I grabbed the nearest debugger (xselerator)...
35
by: Marchel | last post by:
For a long time I was a gib fan of Borland C++ Builder with VCL framework and never gave a second look in Microsoft products since I've seen MFC. Anyway, recently Borland decided out of the blue to...
1
by: liam | last post by:
Hi, I have seen this problem is a couple of other places in the group but can't find an answer to it. Basically I have as aspx file that opens properly in Opera but not in IE. IE gives a...
4
by: pei_world | last post by:
I have followed a example from a book exactly, but it seems not working at all. can anyone tell me what is going on? ========= Global.asax.cs ============ public static Entry...
8
by: WvH | last post by:
Hi, When I create a new application, with just one button, then this code works as expected: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles...
4
by: Kiyomi | last post by:
Hello, I am trying to replace my alert message box with a popup page. In my page behind,
13
by: johneecc | last post by:
Hi, I am having a heck of a time trying to figure this one out. I am not a pro with CSS or ASP. I know VBScript fairly well. There is a Expected ')' error in the line with the "a href"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.