slibc
|
Contains those _s functions that were added to C99's /usr/include/stdlib.h. More...
Go to the source code of this file.
Functions | |
constraint_handler_t | set_constraint_handler_s (constraint_handler_t handler) |
The set_constraint_handler function sets a user-specified constraint handler. | |
void | abort_handler_s (const char *restrict msg, void *restrict ptr, errno_t error) |
The abort handler gives out an errormessage on stderr before it ends the program with the function abort. | |
void | ignore_handler_s (const char *restrict msg, void *restrict ptr, errno_t error) |
the ignore_handler_s is used to ignore constraint violations it does nothing | |
errno_t | getenv_s (size_t *restrict len, char *restrict value, rsize_t maxsize, const char *restrict name) |
The getenv_s function gets the value of an environment variable. | |
errno_t | qsort_s (void *base, rsize_t nmemb, rsize_t size, int(*compar)(const void *x, const void *y, void *context), void *context) |
This function sorts an array in ascending order. | |
void * | bsearch_s (const void *key, const void *base, rsize_t nmemb, rsize_t size, int(*compar)(const void *, const void *, void *context), void *context) |
This function performs a binary search of a sorted array. | |
Variables | |
SLIBC_BEGIN_DECLS typedef void(* | constraint_handler_t )(const char *restrict msg, void *restrict ptr, errno_t error) |
Definition of callback-type constraint_handler_t. |
Contains those _s functions that were added to C99's /usr/include/stdlib.h.
void* bsearch_s | ( | const void * | key, |
const void * | base, | ||
rsize_t | nmemb, | ||
rsize_t | size, | ||
int(*)(const void *, const void *, void *context) | compar, | ||
void * | context | ||
) |
This function performs a binary search of a sorted array.
The array (given by base, nmemb and size) is searched for a member that is the same as the object pointed to by key.
[in] | key | points to the object to be matched |
[in] | base | points to the start of the array |
[in] | nmemb | specifies the number of elements in the array |
[in] | size | gives the size of an individual array argument |
[in] | compar | a pointer to the comparison function |
[in,out] | context | may hold a user-defined value or Null. This value will be supplied as an extra-argument to the comparison function. |
errno_t getenv_s | ( | size_t *restrict | len, |
char *restrict | value, | ||
rsize_t | maxsize, | ||
const char *restrict | name | ||
) |
The getenv_s function gets the value of an environment variable.
Developers often make wrong assumptions about the size of environment variables. Since a local attacker can set environment variables, the environment has to be considered evil as every other input. The getenv_s functions forces the programmer to supply a maximum buffer size.
[out] | len | If len is not Null, the integer pointed to by len will be set to the length of the variable's value (one needs a buffer with length + 1 for storing the string) |
[out] | value | contains the environment variable's value on success |
[in] | maxsize | the size of the buffer pointed to by value |
[in] | name | the name of the environment variable to search for |
char env_value[255]; getenv_s(NULL, env_value, sizeof(env_value), "PATH");
errno_t qsort_s | ( | void * | base, |
rsize_t | nmemb, | ||
rsize_t | size, | ||
int(*)(const void *x, const void *y, void *context) | compar, | ||
void * | context | ||
) |
This function sorts an array in ascending order.
The array is sorted according to the specified comparison function. Besides performing several runtime-checks (see rcs), the only difference is that the comparison function accepts an additional argument for the caller's use.
[in,out] | base | points to the start of the array |
[in] | nmemb | specifies the number of elements in the array |
[in] | size | gives the size of an individual array argument |
[in] | compar | a pointer to the comparison function |
[in,out] | context | may hold a user-defined value or Null. This value will be supplied as an extra-argument to the comparison function. |
The set_constraint_handler function sets a user-specified constraint handler.
The constraint handler is called whenever a runtime constraint violation is detected. If, for example, a user calls strcpy_s(NULL, 0, source) the currently set runtime constraint handler will be invoked. The constraint handler is specific to each thread.
If the application does not set its own constraint handler, the default constraint handler is called. In our implementation the default constraint handler is abort_handler_s.
[in] | handler | a pointer to the new handler function |
SLIBC_BEGIN_DECLS typedef void(* constraint_handler_t)(const char *restrict msg, void *restrict ptr, errno_t error) |
Definition of callback-type constraint_handler_t.
All SLIBC-functions invoke the constraint handler in case of a constraint violation.