By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,506 Members | 1,881 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,506 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.