Solved

VS2005 C runtime and _set_invalid_parameter_handler

Posted on 2006-11-08
4
1,497 Views
Last Modified: 2012-06-27
VS2005's C runtime has security enhancements that catch problems at runtime with functions like:

strcpy_s

there is a mechanism to setup _invalid_parameter_handler using the _setup_invalid_parameter_handler function.  If a runtime event happens the handler gets called.  Ok, that's good.

But when this happens (in the field as always) there does not seem to be any way to relate this back to the source.  You get line number information but it's from the source of strcpy_s and not my code that calls strcpy_s.

How can such an error be referenced back to a source code line that I've written?
0
Comment
Question by:jhance
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 17897314
0
 
LVL 32

Author Comment

by:jhance
ID: 17897716
rajeev,

I read through the comments at the link you referenced, but I don't see the connection to my question...
0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 500 total points
ID: 17898171
>>>> How can such an error be referenced back to a source code line that I've written?

Don't see a way to do so by using standard means. The call stack is only available in debug mode.

If you don't mind to take some efforts and are not afraid of using macros you might call wrapper functions instead of the original secure functions like that:

#define STRCPY_S(dest, siz, src) mystrcpy_s(__FILE__, __LINE__, dest, siz, src)

errno_t mystrcpy_s(const char srcfile[], int lineNo,
                   char *strDestination, size_t sizeInBytes, const char *strSource)
{
    Global::g_strLastSrcFile   = srcfile;
    Global::g_strLastLineNo    = lineNo;
    Global::g_strLastFunction  = "strcpy_s";
    return strcpy_s( strDestination, sizeInBytes, strSource);
}

These 'global' variables may be static members of a class Global or global variables in a namespace.

If doing so for all 'secure' runtime functions you could evaluate that information in your invalisd parameter handler.

Regards, Alex
 
0
 
LVL 32

Author Comment

by:jhance
ID: 17933878
I was hoping for something cleaner but it seems this is the best there is...

Thanks...
0

Featured Post

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question