Wiki Markup |
---|
Most functions defined by ISO/IEC TR 24731-1-2007 include as part of their specification a list of runtime constraints, violations of which can be consistently handled at runtime \[[ISO/IEC TR 24731-1-2007|AA. C References#ISO/IEC TR 24731-1-2007]\]. Library implementations must verify that the runtime constraints for a function are not violated by the program. If a runtime constraint is violated, the runtime constraint handler currently registered with {{ |
set_constraint_handler_s()}} is called. |
Wiki Markup |
---|
Section 6.6.1 states \[[ISO/IEC TR 24731-1-2007|AA. C References#ISO/IEC TR 24731-1-2007]\]: |
When the handler is called, it is passed the following arguments in the following order:
- A pointer to a character string describing the runtime constraint violation.
- A null pointer or a pointer to an implementation-defined object.
- If the function calling the handler has a return type declared as
errno_t
, the return value of the function is passed. Otherwise, a positive value of typeerrno_t
is passed.The implementation has a default constraint handler that is used if no calls to the
set_constraint_handler_s()
function have been made or the handler argument toset_constraint_handler_s()
is a null pointer. The behavior of the default handler is implementation-defined, and it may cause the program to exit or abort.
Wiki Markup |
---|
And Section 6.1.4 states |
These runtime constraints are requirements on the program using the library.
and
\[[ISO/IEC TR 24731-1-2007|AA. C References#ISO/IEC TR 24731-1-2007]\]: |
The runtime constraint handler might not return. If the handler does return, the library function whose runtime constraint was violated shall return some indication of failure as given by the returns section in the function's specification.
These runtime constraint handlers mitigate some of the potential insecurity caused by in-band error indicators (see ERR02-A. Avoid in-band error indicators).
Non-Compliant Code Example (TR24731-1)
In this non-compliant example, the strcpy_s()
function is called, but no runtime constraint handler has been explicitly registered. As a result, the implementation-defined default handler will be called on a runtime error.
...
Wiki Markup |
---|
\[[ISO/IEC TR 24731-1-2007|AA. C References#ISO/IEC TR 24731-1-2007]\] Section 6.1.4, "Runtime-constraint violations", and Section 6.6.1, "Runtime-constraint handling"
\[[MSDN|AA. C References#MSDN]\] "[Parameter Validation|http://msdn.microsoft.com/en-us/library/ksazx244.aspx]" |
...