Solved

VS2005 C runtime and _set_invalid_parameter_handler

Posted on 2006-11-08
4
1,489 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
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using Diagnostic tools in VS2015: Unresoved allocations 19 123
C++ mouse_event mouse look 7 109
show out valin of json for debugging in visaul c++ 1 47
C++ Code Issue 4 37
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

679 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