473,396 Members | 1,748 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,396 software developers and data experts.

How to disable _SECURE_ATL macro

Dear All,
I have upgraded my source code from VS 2003 to VS 2005, and my code is
breaking due to the _SECURE_ATL macro in some methods of ATL. As it is
executed all the times though there is also a non-secure block of code
defined alongwith it. Is there any way of disabling this macro...as mere
#define _SECURE_ATL 0, in the stdafx.h or somewhere between the code is not
working.

Regards,

--
Ejaz ul Haq
Jan 16 '06 #1
11 5239
from atldef.h:
#ifndef _SECURE_ATL
#define _SECURE_ATL 1
#endif // _SECURE_ATL

atldef.h is included in (among others) atlbase.h
you can add "_SECURE_ATL=0" to the preprocessor definitions of your project
to define that macro before atldef.h is included. that, however leads to a
large number of warnings because then you are using depreceated functions.

you can get rid of those by adding the following to your preprocessor defs.
_CRT_SECURE_NO_DEPRECATE;_SECURE_SCL=0;_SECURE_ATL =0

to get rid of the warnings for other depreceated functions, add at the top
of your StdAfx.h file

#pragma warning(disable : 4996)

of course, it would be MUCH better to port your code to use the new, secure
functions because doing the things mentioned above will leave you open to
lots of potential problems.

kind regards,
Bruno.

"Ejaz ul Haq" <Ej*******@discussions.microsoft.com> wrote in message
news:58**********************************@microsof t.com...
Dear All,
I have upgraded my source code from VS 2003 to VS 2005, and my code is
breaking due to the _SECURE_ATL macro in some methods of ATL. As it is
executed all the times though there is also a non-secure block of code
defined alongwith it. Is there any way of disabling this macro...as mere
#define _SECURE_ATL 0, in the stdafx.h or somewhere between the code is
not
working.

Regards,

--
Ejaz ul Haq

Jan 16 '06 #2
"Bruno van Dooren" <br**********************@hotmail.com> wrote
you can get rid of those by adding the following to your preprocessor
defs.
_CRT_SECURE_NO_DEPRECATE;_SECURE_SCL=0;_SECURE_ATL =0

to get rid of the warnings for other depreceated functions, add at the top
of your StdAfx.h file

#pragma warning(disable : 4996)

of course, it would be MUCH better to port your code to use the new,
secure functions because doing the things mentioned above will leave you
open to lots of potential problems.

FWIW, I completely, entirely and utterly disagree with that statement.
Almost all these come at a price. There are some things that are indeed
reasonable in the secure C library:

- functions that return internal buffers (e.g. tmpnam) or otherwise
require internal buffers (notably qsort)
- functions that write unpredictable amounts of data to a buffer
(scanf with certain format strings)

However, there are places where you're typically perfectly aware
of the buffer size. For instance, deprecating memcpy in favor of
memcpy_s is a quite stupid motion, IMHO.

Things are worse for the Standard C++ Library (VC++ uses the
acronym SCL for it - how do you know the don't mean Standard
C Library? I don't know).
They can have significant impact on performance and working set.
Worse, some of the "secure functionality" violate the requirements
of the C++ standard, which could in fact introduce security issues
not present in your original code (granted, this is quite unlikely).
And then there's _SECURE_SCL_THROWS, which is probably
worse than the disease.
Of course, the "Secure SCL" does not catch all security relevant
bugs - in fact I don't think I've ever seen an issue in an app we
shipped where _SECURE_SCL had helped.

Bottom line: The "Secure SCL" comes at a price and I believe
the tradeoffs don't fit nicely with the philosophy of the C++
language. And never ever defined _SECURE_SCL_THROWS=1
unless you absolutely know what you're doing.

-hg

Jan 16 '06 #3
However, there are places where you're typically perfectly aware
of the buffer size. For instance, deprecating memcpy in favor of
memcpy_s is a quite stupid motion, IMHO.


the problem with memcpy is that if you are interacting with code that you
didn't write
yourself, you cannot be sure that using it is safe.
in those cases it is better to always use memcpy_s because you have to
verify with all external buffers anway.

unless we are talking about some piece of code where performance is
critical, i would advise to use the new libaries because they are much
safer, and in 99.9 % of the cases, the added CPU cycles are un-important.

if performance really is critical then that could be a reason for using the
un-safe functions, but that shouldn't be the default choice. security and
stability issues are much more commonplace than performance issues for most
(but not all) code.

kind regards,
Bruno.
Jan 16 '06 #4
On Mon, 16 Jan 2006 17:14:45 +0100, "Bruno van Dooren"
<br**********************@hotmail.com> wrote:
However, there are places where you're typically perfectly aware
of the buffer size. For instance, deprecating memcpy in favor of
memcpy_s is a quite stupid motion, IMHO.


the problem with memcpy is that if you are interacting with code that you
didn't write
yourself, you cannot be sure that using it is safe.
in those cases it is better to always use memcpy_s because you have to
verify with all external buffers anway.

unless we are talking about some piece of code where performance is
critical, i would advise to use the new libaries because they are much
safer, and in 99.9 % of the cases, the added CPU cycles are un-important.

if performance really is critical then that could be a reason for using the
un-safe functions, but that shouldn't be the default choice. security and
stability issues are much more commonplace than performance issues for most
(but not all) code.


I'm pretty much with Holger on this one. The "safe" functions don't provide
any additional safety for people who use the "unsafe" functions correctly.
As I see it, the primary value in deprecating the "unsafe" functions in
favor of "safe" ones that have size parameters is to force people to think
a little harder about what they're saying. The thing about the "safe"
functions is that without deprecating the traditional, "unsafe" functions,
no one would use the "safe" functions, and you couldn't force people to
think a little harder. Unfortunately, the effect it has on those who've
thought long and hard for years is to irritate them. :) And make no mistake
about the "safe" functions, mistakes will still be made; I reported at
least two bugs in which someone "fixed" MSDN examples by supplying size
arguments in the form of sizeof(ptr) when he really needed to provide an
array size.

Note also the compiler doesn't require you to check the return value of the
"safe" functions. However, MS did get the parameter validation default
behavior right. Unlike what Windows did with lstrcpy, having it swallow
access violations and return an error code which no one checks because
everyone expects lstrcpy to succeed, the CRT invokes an invalid parameter
handler which raises an access violation by default. The question is, do
these functions treat all errors they detect in this way? Offhand, I don't
know, but I hope they do. I also hope those who "want to keep my program
from crashing" never discover _set_invalid_parameter_handler.

--
Doug Harrison
Visual C++ MVP
Jan 16 '06 #5
I'm pretty much with Holger on this one. The "safe" functions don't
provide
any additional safety for people who use the "unsafe" functions correctly. that 5s tr4e As I see it, the primary value in deprecating the "unsafe" functions in
favor of "safe" ones that have size parameters is to force people to think
a little harder about what they're saying. The thing about the "safe"
functions is that without deprecating the traditional, "unsafe" functions,
no one would use the "safe" functions, and you couldn't force people to
think a little harder. Unfortunately, the effect it has on those who've
thought long and hard for years is to irritate them. :) And make no
mistake
about the "safe" functions, mistakes will still be made; I reported at
least two bugs in which someone "fixed" MSDN examples by supplying size
arguments in the form of sizeof(ptr) when he really needed to provide an
array size.

Note also the compiler doesn't require you to check the return value of
the
"safe" functions. However, MS did get the parameter validation default
behavior right. Unlike what Windows did with lstrcpy, having it swallow
access violations and return an error code which no one checks because
everyone expects lstrcpy to succeed, the CRT invokes an invalid parameter
handler which raises an access violation by default. The question is, do
these functions treat all errors they detect in this way? Offhand, I don't
know, but I hope they do. I also hope those who "want to keep my program
from crashing" never discover _set_invalid_parameter_handler.

--
Doug Harrison
Visual C++ MVP

Jan 16 '06 #6
"Bruno van Dooren" <br**********************@hotmail.com> wrote
However, there are places where you're typically perfectly aware
of the buffer size. For instance, deprecating memcpy in favor of
memcpy_s is a quite stupid motion, IMHO.
the problem with memcpy is that if you are interacting with code that you
didn't write
yourself, you cannot be sure that using it is safe.
in those cases it is better to always use memcpy_s because you have to
verify with all external buffers anway.

I don't quite understand what you're trying to say. Memcpy's contract
clearly defines the size of the buffer accessed.
unless we are talking about some piece of code where performance is
critical, i would advise to use the new libaries because they are much
safer, and in 99.9 % of the cases, the added CPU cycles are un-important.
I guess we are not talking about the same thing then. My main complaint
is about Secure SCL which most definitely is not "much safer".

Re memcpy_s et al.: What makes you believe that these functions are
much safer? Carrying the buffer size is tedious and I wouldn't be surprised
if folks just copied the buffer size to memcpy as the fourth paramter.
E.g.
memcpy( foo, bar, size );
becomes
memcpy_s( foo, bar, size, size );

There is obviously no value in this transformation.
Additionally, there are already superior solutions to this problem
by using C++ wrappers. E.g. std::string or std::valarray or any
of the standard containers.
if performance really is critical then that could be a reason for using
the un-safe functions, but that shouldn't be the default choice. security
and stability issues are much more commonplace than performance issues for
most (but not all) code.
I'm afraid I disagree. You don't just throw a switch at the compiler and
your program is magically secure. There is a lot of work involved that
will render your code slower, more complex and less portable. Deprecating
standard functions by default is an extrembly poor choice IMHO.

If you consider buffer management too hard, don't want to use a
managing wrapper and don't care about performance, working set etc.,
you'd probably be better off with another programming language.
Java & C# come to mind.

Obviously, this is a matter of philosophy and maybe personal taste.
However, I definitely do not concur with your initial statement
of course, it would be MUCH better to port your code to use the new, secure
functions because doing the things mentioned above will leave you open to
lots of potential problems.


OTOH, that doesn't necessarily mean you should never use the secure
libraries. But that's what I've done and probably will in the future.

Just my two cents
-hg
Jan 16 '06 #7
I am sorry if i voiced my opinion too strongly. I understand your position.
I also would not update a known good code base just for fun, but in a recent
large project where i was lead programmer, I was far too often a victim of
people not doing correct buffer checks.

The team i was working with was not experienced, and 'forgot' range checking
a lot of times. (that and the fact that pointers have to point somewhere).
if i could have forced everyone then to use the safe functions, it would
have saved the whole team lots of debugging time during the integration
phase.

if nothing else, it would have forced them to wonder why they had to supply
a size parameter, just like you said.

kind regards,
Bruno.
Jan 16 '06 #8
On Mon, 16 Jan 2006 18:54:02 +0100, "Bruno van Dooren"
<br**********************@hotmail.com> wrote:
I am sorry if i voiced my opinion too strongly. I understand your position.
I also would not update a known good code base just for fun, but in a recent
large project where i was lead programmer, I was far too often a victim of
people not doing correct buffer checks.

The team i was working with was not experienced, and 'forgot' range checking
a lot of times. (that and the fact that pointers have to point somewhere).
if i could have forced everyone then to use the safe functions, it would
have saved the whole team lots of debugging time during the integration
phase.

if nothing else, it would have forced them to wonder why they had to supply
a size parameter, just like you said.


I'm glad you posted this, because I think it's exactly the scenario the
"safe" functions can help. I just wish there had been a good alternative to
deprecating a bunch of standard functions by default.

--
Doug Harrison
Visual C++ MVP
Jan 16 '06 #9
Hi Guys,
Things are working in the release builds but the problem is still persisting
with the debug ones, any ideas about that.

Regards
--
Ejaz ul Haq
"Bruno van Dooren" wrote:
from atldef.h:
#ifndef _SECURE_ATL
#define _SECURE_ATL 1
#endif // _SECURE_ATL

atldef.h is included in (among others) atlbase.h
you can add "_SECURE_ATL=0" to the preprocessor definitions of your project
to define that macro before atldef.h is included. that, however leads to a
large number of warnings because then you are using depreceated functions.

you can get rid of those by adding the following to your preprocessor defs.
_CRT_SECURE_NO_DEPRECATE;_SECURE_SCL=0;_SECURE_ATL =0

to get rid of the warnings for other depreceated functions, add at the top
of your StdAfx.h file

#pragma warning(disable : 4996)

of course, it would be MUCH better to port your code to use the new, secure
functions because doing the things mentioned above will leave you open to
lots of potential problems.

kind regards,
Bruno.


Jan 17 '06 #10
make sure that _ATL_DEBUG_INTERFACES is not defined.

if you open the atl headers (atlbase.h for example) with VS2005, the ide
will gray out the parts of the headers which are disabled by conditional
compilation statements.

this way, you can easily check which macros are defined or not defined.

note that if you change preprocessor defs, intellisense needs to update
first before you see the results. this may take a few seconds.

kind regards,
Bruno.

"Ejaz ul Haq" wrote:
Hi Guys,
Things are working in the release builds but the problem is still persisting
with the debug ones, any ideas about that.

Regards
--
Ejaz ul Haq
"Bruno van Dooren" wrote:
from atldef.h:
#ifndef _SECURE_ATL
#define _SECURE_ATL 1
#endif // _SECURE_ATL

atldef.h is included in (among others) atlbase.h
you can add "_SECURE_ATL=0" to the preprocessor definitions of your project
to define that macro before atldef.h is included. that, however leads to a
large number of warnings because then you are using depreceated functions.

you can get rid of those by adding the following to your preprocessor defs.
_CRT_SECURE_NO_DEPRECATE;_SECURE_SCL=0;_SECURE_ATL =0

to get rid of the warnings for other depreceated functions, add at the top
of your StdAfx.h file

#pragma warning(disable : 4996)

of course, it would be MUCH better to port your code to use the new, secure
functions because doing the things mentioned above will leave you open to
lots of potential problems.

kind regards,
Bruno.

Jan 17 '06 #11
"Bruno van Dooren" <br**********************@hotmail.com> wrote in message
news:e9****************@TK2MSFTNGP10.phx.gbl...

of course, it would be MUCH better to port your code to use the new,
secure functions because doing the things mentioned above will leave you
open to lots of potential problems.

kind regards,
Bruno.


.... in addition to the other points made, it can't really be done if you
want portable (cross-platform) code.
Jan 19 '06 #12

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

Similar topics

1
by: Scott Wallace | last post by:
Anyone know how to disable macros when access an Excel file through automation? I have an Excel file that fires macros when it is opened. I need to automate reading values from the file through a...
3
by: bonehead | last post by:
Okay, here's a question I should have posted a very very long time ago. I'd like to prevent the user from being able to bypass certain error handling and updating functions that are programmed into...
7
by: Mark | last post by:
Help, please!! I am running MS Access 2000. I copied code from Michael Kaplan's website (see below) to disable the shift key for all non-admin users. I pasted the code into a new function. ...
4
by: Rich Wallace | last post by:
Is there a way to open an Excel file and either respond to or supress the Macro warning window via VB.NET? Dim oExcel As Excel.Workbook Dim sFilePath As String = "C:\DailyReport.xls" oExcel...
1
by: Troy | last post by:
How do I answer the disable macro prompt automatically when opening an Excel workbook? We are using Excel 97 and 2002. In 2002 we want the Medium security (prompt user) to safeguard against e-mail...
16
by: MLH | last post by:
If I give someone a runtime app, they can open the database window by pressing the F-11 key. How to prevent???
9
by: JBuckner | last post by:
My macro uses the Send Object (VBA Item.Send) function to email a spreadsheet to an Outlook contact list. I want the function to be completely automatic but Outlook displays a security warning...
19
by: RedDevilDan | last post by:
I am working on a Memory Footprint Reduction project. I came across an idea to disable all printf statements so that less memory is required. In addition, when there is no single printf statement,...
7
by: devecibasi | last post by:
Hi all, I have a macro that executes ~200 queries which modify the data, create some tables etc. The macro runs when the user clicks a button on a form. I would like the queries to be invisible...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.