safec
3.3
Safe C Library - ISO TR24731 Bounds Checking Interface
|
#include "safe_config.h"
#include "safe_lib_errno.h"
#include "safe_types.h"
#include "safe_compile.h"
#include <wchar.h>
Macros | |
#define | EXTERN extern |
#define | RSIZE_MAX_MEM16 ( RSIZE_MAX_MEM/2 ) |
#define | RSIZE_MAX_MEM32 ( RSIZE_MAX_MEM/4 ) |
#define | RSIZE_MAX_WMEM ( RSIZE_MAX_MEM/sizeof(wchar_t) ) |
#define | memcpy_s(dest, dmax, src, slen) _memcpy_s_chk(dest,dmax,src,slen,BOS(dest),BOS(src)) |
This function copies at most slen bytes from src to dest, up to dmax resp. More... | |
#define | memmove_s(dest, dmax, src, slen) _memmove_s_chk(dest,dmax,src,slen,BOS(dest),BOS(src)) |
The memmove_s function copies slen bytes from the region pointed to by src into the region pointed to by dest . More... | |
#define | memset_s(dest, dmax, value, n) _memset_s_chk(dest,dmax,value,n,BOS(dest)) |
Sets the first n bytes starting at dest to the specified value, but maximal dmax bytes. More... | |
#define | memset16_s(dest, dmax, value, n) _memset16_s_chk(dest,dmax,value,n,BOS(dest)) |
Sets the first n uint16_t values starting at dest to the specified value, but maximal dmax bytes. More... | |
#define | memset32_s(dest, dmax, value, n) _memset32_s_chk(dest,dmax,value,n,BOS(dest)) |
Sets n uint32_t values starting at dest to the specified value, but maximal dmax bytes. More... | |
#define | memcmp_s(dest, dmax, src, slen, diff) _memcmp_s_chk(dest,dmax,src,slen,diff,BOS(dest),BOS(src)) |
Compares memory until they differ, and their difference sign (-1,0,1) is returned in diff . More... | |
#define | memcmp16_s(dest, dlen, src, slen, diff) _memcmp16_s_chk(dest,dlen,src,slen,diff,BOS(dest),BOS(src)) |
Compares memory in uint16_t slices until they differ, and their difference is returned in diff. More... | |
#define | memcmp32_s(dest, dlen, src, slen, diff) _memcmp32_s_chk(dest,dlen,src,slen,diff,BOS(dest),BOS(src)) |
Compares memory in uint32_t slices until they differ, and their difference is returned in diff. More... | |
#define | memcpy16_s(dest, dmax, src, slen) _memcpy16_s_chk(dest,dmax,src,slen,BOS(dest),BOS(src)) |
This function copies at most slen uint16_t's from src to dest, up to dmax bytes. More... | |
#define | memcpy32_s(dest, dmax, src, slen) _memcpy32_s_chk(dest,dmax,src,slen,BOS(dest),BOS(src)) |
This function copies at most slen uint32_t's from src to dest, up to dmax. More... | |
#define | memmove16_s(dest, dmax, src, slen) _memmove16_s_chk(dest,dmax,src,slen,BOS(dest),BOS(src)) |
The memmove16_s function copies slen uint16_t from the region pointed to by src into the region pointed to by dest. More... | |
#define | memmove32_s(dest, dmax, src, slen) _memmove32_s_chk(dest,dmax,src,slen,BOS(dest),BOS(src)) |
The memmove32_s function copies slen uint32_t's from the region pointed to by src into the region pointed to by dest. More... | |
#define | memzero_s(dest, len) _memzero_s_chk(dest,len,BOS(dest)) |
Zeros len bytes starting at dest. More... | |
#define | memzero16_s(dest, len) _memzero16_s_chk(dest,len,BOS(dest)) |
Zeros len uint16_t's starting at dest. More... | |
#define | memzero32_s(dest, len) _memzero32_s_chk(dest,len,BOS(dest)) |
Zeros len uint32_t's starting at dest. More... | |
#define | memchr_s(dest, dmax, ch, result) _memchr_s_chk(dest,dmax,ch,result,BOS(dest)) |
Finds the first occurrence of ch (after conversion to unsigned char as if by (unsigned char)ch ) in the null-terminated buffer pointed to by dest (each character interpreted as unsigned char ). More... | |
#define | memrchr_s(dest, dmax, ch, result) _memrchr_s_chk(dest,dmax,ch,result,BOS(dest)) |
Finds the last occurrence of ch (after conversion to char as if by (char)ch) in the null-terminated byte string pointed to by dest (each character interpreted as unsigned char). More... | |
#define | timingsafe_bcmp(b1, b2, n) _timingsafe_bcmp_chk(b1,b2,n,BOS(b1),BOS(b2)) |
Compare all memory bytes. More... | |
#define | timingsafe_memcmp(b1, b2, len) _timingsafe_memcmp_chk(b1,b2,len,BOS(b1),BOS(b2)) |
Compare all memory bytes. More... | |
#define | memccpy_s(dest, dmax, src, c, n) _memccpy_s_chk(dest,dmax,src,c,n,BOS(dest),BOS(src)) |
memccpy_s copies no more than n bytes from memory area src to memory area dest, stopping when the character c is found. More... | |
#define | wmemcpy_s(dest, dlen, src, count) _wmemcpy_s_chk(dest,dlen,src,count,BOS(dest),BOS(src)) |
This function copies at most count wchar_t's from src to dest, up to dlen. More... | |
#define | wmemmove_s(dest, dlen, src, count) _wmemmove_s_chk(dest,dlen,src,count,BOS(dest),BOS(src)) |
The wmemmove_s function copies count wchar_t's from the region pointed to by src into the region pointed to by dest. More... | |
#define | wmemcmp_s(dest, dlen, src, slen, diff) _wmemcmp_s_chk(dest,dlen,src,slen,diff,BOS(dest),BOS(src)) |
Compares buffers of wide chars until they differ, and return 0 if the same or -1 or 1 in diff. More... | |
Functions | |
EXTERN constraint_handler_t | set_mem_constraint_handler_s (constraint_handler_t handler) |
The set_mem_constraint_handler_s function sets the runtime-constraint handler to be handler. More... | |
EXTERN errno_t | _memcpy_s_chk (void *restrict dest, rsize_t dmax, const void *restrict src, rsize_t slen, const size_t destbos, const size_t srcbos) BOS_CHK_BUTZERO(dest |
EXTERN errno_t slen | BOS_OVR2_BUTZERO (src, slen) BOS_ATTR(_BOS_KNOWN(dest) &&_BOS_KNOWN(src) &&((dest > src &&(char *) dest<(char *) src+slen)||(src > dest &&(char *) src<(char *) dest+dmax)) |
EXTERN errno_t | _memmove_s_chk (void *dest, rsize_t dmax, const void *src, rsize_t slen, const size_t destbos, const size_t srcbos) BOS_CHK_BUTZERO(dest |
EXTERN errno_t slen | BOS_OVR2_BUTZERO (src, slen) VAL_OVR2_BUTZERO(slen |
EXTERN errno_t | _memset_s_chk (void *dest, rsize_t dmax, int value, rsize_t n, const size_t destbos) BOS_ATTR(n &&(_BOS_OVR(dest |
EXTERN errno_t n n n overflow dest dmax | VAL_OVR2 (value, 255) |
EXTERN errno_t | _memset16_s_chk (uint16_t *dest, rsize_t dmax, uint16_t value, rsize_t n, const size_t destbos) BOS_ATTR(n &&(_BOS_OVR(dest |
EXTERN errno_t | _memset32_s_chk (uint32_t *dest, rsize_t dmax, uint32_t value, rsize_t n, const size_t destbos) BOS_ATTR(n &&(_BOS_OVR(dest |
EXTERN errno_t | _memcmp_s_chk (const void *dest, rsize_t dmax, const void *src, rsize_t slen, int *diff, const size_t destbos, const size_t srcbos) BOS_CHK(dest) BOS_OVR2(src |
EXTERN errno_t slen | BOS_NULL (diff) VAL_OVR2_BUTZERO(slen |
EXTERN errno_t | _memcmp16_s_chk (const uint16_t *dest, rsize_t dlen, const uint16_t *src, rsize_t slen, int *diff, const size_t destbos, const size_t srcbos) VAL_OVR2_BUTZERO(slen |
EXTERN errno_t | _memcmp32_s_chk (const uint32_t *dest, rsize_t dlen, const uint32_t *src, rsize_t slen, int *diff, const size_t destbos, const size_t srcbos) VAL_OVR2_BUTZERO(slen |
EXTERN errno_t | _memcpy16_s_chk (uint16_t *dest, rsize_t dmax, const uint16_t *src, rsize_t slen, const size_t destbos, const size_t srcbos) VAL_OVR2_BUTZERO(slen |
EXTERN errno_t | _memcpy32_s_chk (uint32_t *dest, rsize_t dmax, const uint32_t *src, rsize_t slen, const size_t destbos, const size_t srcbos) VAL_OVR2_BUTZERO(slen |
EXTERN errno_t | _memmove16_s_chk (uint16_t *dest, rsize_t dmax, const uint16_t *src, rsize_t slen, const size_t destbos, const size_t srcbos) VAL_OVR2_BUTZERO(slen |
EXTERN errno_t | _memmove32_s_chk (uint32_t *dest, rsize_t dmax, const uint32_t *src, rsize_t slen, const size_t destbos, const size_t srcbos) VAL_OVR2_BUTZERO(slen |
EXTERN errno_t | _memzero_s_chk (void *dest, rsize_t dmax, const size_t destbos) BOS_CHK(dest) |
EXTERN errno_t | _memzero16_s_chk (uint16_t *dest, rsize_t len, const size_t destbos) BOS_CHK2(dest |
EXTERN errno_t | _memzero32_s_chk (uint32_t *dest, rsize_t len, const size_t destbos) BOS_CHK2(dest |
EXTERN errno_t | _memchr_s_chk (const void *restrict dest, rsize_t dmax, const int ch, void **result, const size_t destbos) BOS_NULL(result) |
EXTERN errno_t | _memrchr_s_chk (const void *restrict dest, rsize_t dmax, const int ch, void **result, const size_t destbos) BOS_CHK(dest) VAL_OVR2(ch |
EXTERN errno_t | BOS_NULL (result) |
EXTERN int | _timingsafe_bcmp_chk (const void *b1, const void *b2, size_t n, const size_t destbos, const size_t srcbos) BOS_OVR2(b1 |
EXTERN int n | BOS_OVR2 (b2, n) |
EXTERN int | _timingsafe_memcmp_chk (const void *b1, const void *b2, size_t len, const size_t destbos, const size_t srcbos) BOS_OVR2(b1 |
EXTERN int len | BOS_OVR2 (b2, len) |
EXTERN errno_t | _memccpy_s_chk (void *dest, rsize_t dmax, const void *src, int c, rsize_t n, const size_t destbos, const size_t srcbos) BOS_CHK(dest) BOS_OVR2(src |
EXTERN errno_t n | VAL_OVR2 (c, 255) VAL_OVR2_BUTZERO(n |
EXTERN errno_t | _wmemcpy_s_chk (wchar_t *restrict dest, rsize_t dmax, const wchar_t *restrict src, rsize_t smax, const size_t destbos, const size_t srcbos) BOSW_CHK_BUTZERO(dest |
EXTERN errno_t smax | BOSW_OVR2_BUTZERO (src, smax) |
EXTERN errno_t | _wmemmove_s_chk (wchar_t *dest, rsize_t dmax, const wchar_t *src, rsize_t smax, const size_t destbos, const size_t srcbos) BOSW_CHK_BUTZERO(dest |
EXTERN errno_t | _wmemcmp_s_chk (const wchar_t *dest, rsize_t dmax, const wchar_t *src, rsize_t slen, int *diff, const size_t destbos, const size_t srcbos) BOSW_CHK(dest) BOSW_CHK2(src |
Variables | |
EXTERN errno_t slen dest overlaps with | src |
EXTERN errno_t slen | dmax |
EXTERN errno_t | dlen |
#define EXTERN extern |
#define RSIZE_MAX_MEM16 ( RSIZE_MAX_MEM/2 ) |
#define RSIZE_MAX_MEM32 ( RSIZE_MAX_MEM/4 ) |
#define RSIZE_MAX_WMEM ( RSIZE_MAX_MEM/sizeof(wchar_t) ) |
This function copies at most slen bytes from src to dest, up to dmax resp.
sizeof(dest). If slen is zero, the function does nothing.
[out] | dest | pointer to the memory that will be replaced by src. |
[in] | dmax | maximum length of the resulting dest, in bytes |
[in] | src | pointer to the memory that will be copied to dest |
[in] | slen | maximum number bytes of src that can be copied |
EOK | when operation is successful or slen = 0 |
ESNULLP | when dest/src is NULL POINTER |
ESZEROL | when dmax = 0 |
ESLEMAX | when dmax/slen > RSIZE_MAX_MEM |
EOVERFLOW | when dmax/slen > size of dest/src (optionally, when the compiler knows the object_size statically) |
ESLEWRNG | when dmax != size of dest and –enable-error-dmax |
ESNOSPC | when dmax < slen |
ESOVRLP | when src memory overlaps dst |
The memmove_s function copies slen
bytes from the region pointed to by src
into the region pointed to by dest
.
If slen is zero, the function does nothing.
This copying takes place as if the slen bytes from the region pointed to by src are first copied into a temporary array of slen bytes that does not overlap the region pointed to by dest or src, and then the slen bytes from the temporary array are copied into the object region to by dest.
[out] | dest | pointer to the memory that will be replaced by src. |
[in] | dmax | maximum length of the resulting dest, in bytes |
[in] | src | pointer to the memory that will be copied to dest |
[in] | slen | maximum number bytes of src that can be copied |
EOK | when operation is successful or slen = 0 |
ESNULLP | when dest/src is NULL POINTER |
ESZEROL | when dmax = 0 |
ESLEMAX | when dmax/slen > RSIZE_MAX_MEM |
EOVERFLOW | when dmax/slen > size of dest/src (optionally, when the compiler knows the object_size statically) |
ESLEWRNG | when dmax != size of dest and –enable-error-dmax |
ESNOSPC | when dmax < slen |
Sets the first n bytes starting at dest to the specified value, but maximal dmax bytes.
[out] | dest | pointer to memory that will be set to the value |
[in] | dmax | maximum number of bytes to be written |
[in] | value | byte value to be written |
[in] | n | number of bytes to be set |
EOK | when operation is successful or n = 0 |
ESNULLP | when dest is NULL pointer |
ESLEMAX | when dmax/n > RSIZE_MAX_MEM or value > 255 |
EOVERFLOW | when dmax > size of dest (optionally, when the compiler knows the object_size statically) |
ESLEWRNG | when dmax != sizeof(dest) and –enable-error-dmax |
ESNOSPC | when dmax < n |
Sets the first n uint16_t values starting at dest to the specified value, but maximal dmax bytes.
[out] | dest | pointer to memory that will be set to the value |
[in] | dmax | maximum number of bytes to be written |
[in] | value | byte value to be written |
[in] | n | number of short (2-byte) words to be set |
EOK | when operation is successful or n = 0 |
ESNULLP | when dest is NULL POINTER |
ESLEMAX | when dmax > RSIZE_MAX_MEM |
EOVERFLOW | when dmax > size of dest (optionally, when the compiler knows the object_size statically) |
ESLEWRNG | when dmax != size of dest and –enable-error-dmax |
ESLEMAX | when n > RSIZE_MAX_MEM16 |
ESNOSPC | when 2*n > dmax |
Sets n uint32_t values starting at dest to the specified value, but maximal dmax bytes.
[out] | dest | pointer to memory that will be set to the value |
[in] | dmax | maximum number of bytes to be written |
[in] | value | byte value to be written |
[in] | n | number of 4-byte words to be set |
EOK | when operation is successful or n = 0 |
ESNULLP | when dest is NULL POINTER |
ESLEMAX | when dmax > RSIZE_MAX_MEM |
EOVERFLOW | when dmax > size of dest (optionally, when the compiler knows the object_size statically) |
ESLEWRNG | when dmax != size of dest and –enable-error-dmax |
ESLEMAX | when n > RSIZE_MAX_MEM32 |
ESNOSPC | when 4*n > dmax |
#define memcmp_s | ( | dest, | |
dmax, | |||
src, | |||
slen, | |||
diff | |||
) | _memcmp_s_chk(dest,dmax,src,slen,diff,BOS(dest),BOS(src)) |
Compares memory until they differ, and their difference sign (-1,0,1) is returned in
diff
.
If the block of memory is the same, *diff=0
.
dest | pointer to memory to compare against |
src | pointer to the source memory to compare with dest |
dmax | maximum length of dest, in bytes |
slen | length of the source memory block |
*diff | pointer to the diff which is an integer greater than, equal to or less than zero according to whether the object pointed to by dest is greater than, equal to or less than the object pointed to by src. |
EOK | when operation is successful |
ESNULLP | when dst/src is NULL POINTER |
ESZEROL | when dmax/slen = ZERO |
ESLEMAX | when dmax/slen > RSIZE_MAX_MEM |
EOVERFLOW | when dmax/slen > size of dest/src (optionally, when the compiler knows the object_size statically) |
ESLEWRNG | when dmax/slen != size of dest/src and –enable-error-dmax |
ESNOSPC | when dmax < slen |
#define memcmp16_s | ( | dest, | |
dlen, | |||
src, | |||
slen, | |||
diff | |||
) | _memcmp16_s_chk(dest,dlen,src,slen,diff,BOS(dest),BOS(src)) |
Compares memory in uint16_t slices until they differ, and their difference is returned in diff.
If the block of memory is the same, diff=0.
dest | pointer to memory to compare against |
dlen | maximum length of dest, in uint16_t's |
src | pointer to the source memory to compare with dest |
slen | number of uint16_t's from source to be compared |
*diff | pointer to the diff which is an integer greater than, equal to or less than zero according to whether the object pointed to by dest is greater than, equal to or less than the object pointed to by src. |
EOK | when operation is successful |
ESNULLP | when dest/src is NULL POINTER |
ESZEROL | when dlen/slen = ZERO |
ESLEMAX | when dlen/slen > RSIZE_MAX_MEM16 |
EOVERFLOW | when 2*dlen/slen > size of dest/src (optionally, when the compiler knows the object_size statically) |
ESLEWRNG | when 2*dlen/slen != sizeof(dest/src) and –enable-error-dmax |
ESNOSPC | when dlen < slen |
#define memcmp32_s | ( | dest, | |
dlen, | |||
src, | |||
slen, | |||
diff | |||
) | _memcmp32_s_chk(dest,dlen,src,slen,diff,BOS(dest),BOS(src)) |
Compares memory in uint32_t slices until they differ, and their difference is returned in diff.
If the whole block of memory is the same, diff=0.
dest | pointer to memory to compare against |
dlen | maximum length of dest, in uint32_t's |
src | pointer to the source memory to compare with dest |
slen | number of uint32_t's from source to be compared |
*diff | pointer to the diff which is an integer greater than, equal to or less than zero according to whether the object pointed to by dest is greater than, equal to or less than the object pointed to by src. |
EOK | when operation is successful |
ESNULLP | when dest/src is NULL POINTER |
ESZEROL | when dlen/slen = ZERO |
ESLEMAX | when dlen/slen > RSIZE_MAX_MEM32 or > sizeof(dest/src)/4 |
EOVERFLOW | when 4*dlen/slen > size of dest/src (optionally, when the compiler knows the object_size statically) |
ESLEWRNG | when 4*dlen/slen != sizeof(dest/src) and –enable-error-dmax |
ESNOSPC | when dlen < slen |
This function copies at most slen uint16_t's from src to dest, up to dmax bytes.
[out] | dest | pointer to the memory that will be replaced by src. |
[in] | dmax | maximum length of the resulting dest, in bytes |
[in] | src | pointer to the memory that will be copied to dest |
[in] | slen | number of uint16_t's to be copied |
EOK | when operation is successful or slen = 0 |
ESNULLP | when dest/src is NULL POINTER |
ESZEROL | when dmax = ZERO |
ESLEMAX | when dmax > RSIZE_MAX_MEM |
EOVERFLOW | when dmax > size of dest (optionally, when the compiler knows the object_size statically) |
ESLEWRNG | when dmax != sizeof(dest) and –enable-error-dmax |
ESLEMAX | when slen > RSIZE_MAX_MEM16 |
EOVERFLOW | when 2*slen > size of src (optionally, when the compiler knows the object_size statically) |
ESNOSPC | when 2*slen > dmax |
ESOVRLP | when src memory overlaps dest |
This function copies at most slen uint32_t's from src to dest, up to dmax.
[out] | dest | pointer to the memory that will be replaced by src. |
[in] | dmax | maximum length of the resulting dest, in bytes |
[in] | src | pointer to the memory that will be copied to dest |
[in] | slen | number of uint32_t's to be copied |
EOK | when operation is successful or slen = 0 |
ESNULLP | when dest/src is NULL POINTER |
ESZEROL | when dmax = ZERO |
ESLEMAX | when dmax > RSIZE_MAX_MEM |
EOVERFLOW | when dmax > size of dest (optionally, when the compiler knows the object_size statically) |
ESLEWRNG | when dmax != sizeof(dest) and –enable-error-dmax |
ESLEMAX | when slen > RSIZE_MAX_MEM32 |
EOVERFLOW | when 4*slen > size of src (optionally, when the compiler knows the object_size statically) |
ESNOSPC | when 4*slen > dmax |
ESOVRLP | when src memory overlaps dest |
#define memmove16_s | ( | dest, | |
dmax, | |||
src, | |||
slen | |||
) | _memmove16_s_chk(dest,dmax,src,slen,BOS(dest),BOS(src)) |
The memmove16_s function copies slen uint16_t from the region pointed to by src into the region pointed to by dest.
This copying takes place as if the slen uint16_t from the region pointed to by src are first copied into a temporary array of slen uint16_t that does not overlap the regions pointed to by dest or src, and then the slen uint16_t from the temporary array are copied into the region pointed to by dest.
[out] | dest | pointer to the memory that will be replaced by src. |
[in] | dmax | maximum length of the resulting dest, in bytes |
[in] | src | pointer to the memory that will be copied to dest |
[in] | slen | number of uint16_t's to be copied |
EOK | when operation is successful or slen = 0 |
ESNULLP | when dest/src is NULL POINTER |
ESZEROL | when dmax = ZERO |
ESLEMAX | when dmax > RSIZE_MAX_MEM |
EOVERFLOW | when dmax > size of dest (optionally, when the compiler knows the object_size statically) |
ESLEWRNG | when dmax != sizeof(dest) and –enable-error-dmax |
ESLEMAX | when slen > RSIZE_MAX_MEM16 |
EOVERFLOW | when 2*slen > size of src (optionally, when the compiler knows the object_size statically) |
ESNOSPC | when 2*slen > dmax |
#define memmove32_s | ( | dest, | |
dmax, | |||
src, | |||
slen | |||
) | _memmove32_s_chk(dest,dmax,src,slen,BOS(dest),BOS(src)) |
The memmove32_s function copies slen uint32_t's from the region pointed to by src into the region pointed to by dest.
This copying takes place as if the slen uint32_t's from the region pointed to by src are first copied into a temporary array of slen uint32_t's that does not overlap the regions pointed to by dest or src, and then the slen uint32_t's from the temporary array are copied into the region pointed to by dest.
[out] | dest | pointer to the memory that will be replaced by src. |
[in] | dmax | maximum length of the resulting dest, in bytes |
[in] | src | pointer to the memory that will be copied to dest |
[in] | slen | number of uint32_t's to be copied |
EOK | when operation is successful or slen = 0 |
ESNULLP | when dest/src is NULL POINTER |
ESZEROL | when dmax = ZERO |
ESLEMAX | when dmax > RSIZE_MAX_MEM |
EOVERFLOW | when dmax > size of dest (optionally, when the compiler knows the object_size statically) |
ESLEWRNG | when dmax != sizeof(dest) and –enable-error-dmax |
ESLEMAX | when slen > RSIZE_MAX_MEM32 |
EOVERFLOW | when 4*slen > size of src (optionally, when the compiler knows the object_size statically) |
ESNOSPC | when 4*slen > dmax |
Zeros len bytes starting at dest.
[out] | dest | pointer to memory to be zeroed. |
[in] | len | number of bytes to be zeroed |
EOK | when operation is successful |
ESNULLP | when dest is NULL POINTER |
ESZEROL | when len = ZERO |
ESLEMAX | when len > RSIZE_MAX_MEM |
EOVERFLOW | when dmax > size of dest (optionally, when the compiler knows the object_size statically) |
ESLEWRNG | when len != size of dest and –enable-error-dmax |
Zeros len uint16_t's starting at dest.
[out] | dest | pointer to memory to be zeroed. |
[in] | len | number of uint16_t's to be zeroed |
EOK | when operation is successful |
ESNULLP | when dest is NULL POINTER |
ESZEROL | when len = ZERO |
ESLEMAX | when len > RSIZE_MAX_MEM16 |
EOVERFLOW | when 2*dmax > size of dest (optionally, when the compiler knows the object_size statically) |
ESLEWRNG | when len != sizeof(dest)/2 and –enable-error-dmax |
Zeros len uint32_t's starting at dest.
[out] | dest | pointer to memory to be zeroed. |
[in] | len | number of uint32_t's to be zeroed |
EOK | when operation is successful |
ESNULLP | when dest is NULL POINTER |
ESZEROL | when len = ZERO |
ESLEMAX | when len > RSIZE_MAX_MEM32 |
EOVERFLOW | when 2*dmax > size of dest (optionally, when the compiler knows the object_size statically) |
ESLEWRNG | when len != sizeof(dest)/4 and –enable-error-dmax |
Finds the first occurrence of ch
(after conversion to unsigned char as if by (unsigned char)ch
) in the null-terminated buffer pointed to by dest
(each character interpreted as unsigned char
).
[in] | dest | pointer to buffer to compare against |
[in] | dmax | length of dest to search in |
[in] | ch | character to search for |
[out] | result | pointer to result in dest |
EOK | when successfully character found. |
ESNULLP | when dest/result is a NULL pointer |
ESZEROL | when dmax = 0 |
ESLEMAX | when dmax > RSIZE_MAX_MEM or > sizeof(dest) |
ESLEMAX | when ch > 255 |
ESNOTFND | when ch not found in dest |
Finds the last occurrence of ch (after conversion to char as if by (char)ch) in the null-terminated byte string pointed to by dest (each character interpreted as unsigned char).
The terminating null character is considered to be a part of the string and can be found when searching for '\0'.
[in] | dest | pointer to string buffer to compare against |
[in] | dmax | restricted maximum length of dest |
[in] | ch | character to search for |
[out] | result | pointer to char* in dest |
EOK | when successfully character found. |
ESNULLP | when dest/result is a NULL pointer |
ESZEROL | when dmax = 0 |
ESLEMAX | when dmax > RSIZE_MAX_MEM |
EOVERFLOW | when dmax > size of dest (optionally, when the compiler knows the object_size statically) |
ESLEWRNG | when dmax != size of dest and –enable-error-dmax |
ESLEMAX | when ch > 255 |
ESNOTFND | when ch not found in dest |
#define timingsafe_bcmp | ( | b1, | |
b2, | |||
n | |||
) | _timingsafe_bcmp_chk(b1,b2,n,BOS(b1),BOS(b2)) |
Compare all memory bytes.
Return 0 or not zero.
The running time is independent of the byte sequences compared, making them safe to use for comparing secret values such as cryptographic MACs. In contrast, bcmp(3) and memcmp(3) may short-circuit after finding the first differing byte.
b1 | pointer to memory to compare against |
b2 | pointer to the source memory to compare with b1 |
n | number of bytes to compare in both buffers |
0 | if the buffers are equal, or not zero if they are not equal. |
-ESLEMAX | if n > RSIZE_MAX_MEM or > sizeof(b1) or > sizeof(b2) |
#define timingsafe_memcmp | ( | b1, | |
b2, | |||
len | |||
) | _timingsafe_memcmp_chk(b1,b2,len,BOS(b1),BOS(b2)) |
Compare all memory bytes.
Return their difference sign (-1,0,1).
The running time is independent of the byte sequences compared, making them safe to use for comparing secret values such as cryptographic MACs. In contrast, bcmp(3) and memcmp(3) may short-circuit after finding the first differing byte.
b1 | pointer to memory to compare against |
b2 | pointer to the source memory to compare with b1 |
len | number of bytes to compare in both buffers |
-1,0,or | 1 |
-ESLEMAX | if len > RSIZE_MAX_MEM or > sizeof(b1) or > sizeof(b2) |
memccpy_s
copies no more than n bytes from memory area src to memory area dest, stopping when the character c is found.
Throws error if the memory areas overlap. With SAFECLIB_STR_NULL_SLACK defined the rest (max. n bytes, not dmax) is cleared with NULL bytes.
[out] | dest | pointer to the memory that will be replaced by src. |
[in] | dmax | maximum length of the resulting dest, in bytes |
[in] | src | pointer to the memory that will be copied to dest |
[in] | c | character to be found |
[in] | n | maximum number bytes of src that can be copied |
memccpy()
. EOK | when operation is successful or n = 0 |
ESNULLP | when dest/src is NULL POINTER |
ESZEROL | when dmax = ZERO. |
ESLEMAX | when dmax/n > RSIZE_MAX_MEM |
EOVERFLOW | when dmax/n > size of dest (optionally, when the compiler knows the object_size statically) |
ESLEWRNG | when dmax != sizeof(dest) and –enable-error-dmax |
ESNOSPC | when n > dmax |
ESOVRLP | when src memory overlaps dst |
This function copies at most count wchar_t's from src to dest, up to dlen.
If count is zero, the function does nothing.
[out] | dest | pointer to the wide string that will be replaced by src. |
[in] | dlen | maximum length of the resulting dest, in wchar_t |
[in] | src | pointer to the wide string that will be copied to dest |
[in] | count | number of wide characters to copy |
EOK | when operation is successful |
ESNULLP | when dest or src is a NULL POINTER |
ESZEROL | when dlen = ZERO |
ESLEMAX | when dlen/count > RSIZE_MAX_WMEM |
EOVERFLOW | when dlen/count > size of dest/src (optionally, when the compiler knows the object_size statically) |
ESLEWRNG | when dlen != sizeof(dest) and –enable-error-dmax |
ESNOSPC | when dlen < count |
ESOVRLP | when src memory overlaps dst |
#define wmemmove_s | ( | dest, | |
dlen, | |||
src, | |||
count | |||
) | _wmemmove_s_chk(dest,dlen,src,count,BOS(dest),BOS(src)) |
The wmemmove_s function copies count wchar_t's from the region pointed to by src into the region pointed to by dest.
If count is zero, the function does nothing.
This copying takes place as if the count wchar_t's from the region pointed to by src are first copied into a temporary array of count wchar_t's that does not overlap the regions pointed to by dest or src, and then the count wchar_t's from the temporary array are copied into the region pointed to by dest.
[out] | dest | pointer to the memory that will be replaced by src. |
[in] | dlen | maximum length of the resulting dest, in wchar_t |
[in] | src | pointer to the memory that will be copied to dest |
[in] | count | maximum number of wide characters to copy |
EOK | when operation is successful |
ESNULLP | when dest or src is a NULL POINTER |
ESZEROL | when dlen = ZERO |
ESLEMAX | when dlen/count > RSIZE_MAX_WMEM |
EOVERFLOW | when dlen/count > size of dest/src (optionally, when the compiler knows the object_size statically) |
ESLEWRNG | when dlen != sizeof(dest) and –enable-error-dmax |
ESNOSPC | when dlen < count |
#define wmemcmp_s | ( | dest, | |
dlen, | |||
src, | |||
slen, | |||
diff | |||
) | _wmemcmp_s_chk(dest,dlen,src,slen,diff,BOS(dest),BOS(src)) |
Compares buffers of wide chars until they differ, and return 0 if the same or -1 or 1 in diff.
dest | pointer to wchar_t buffer to compare against |
dlen | maximum length of dest, in number of wchar_t |
src | pointer to the source wchar_t buffer to compare with dest |
slen | length of the source memory block |
*diff | pointer to the diff which is -1, 0 or 1 according to whether the object pointed to by dest is greater than, equal to or less than the object pointed to by src. Note that musl returns the diff here. |
EOK | when operation is successful |
ESNULLP | when dest/src is NULL POINTER |
ESZEROL | when dlen/slen = ZERO |
ESLEMAX | when dlen/slen > RSIZE_MAX_WMEM |
EOVERFLOW | when dlen/slen > size of dest/src (optionally, when the compiler knows the object_size statically) |
ESLEWRNG | when dlen != size of dest and –enable-error-dmax |
ESNOSPC | when slen > dlen |
EXTERN constraint_handler_t set_mem_constraint_handler_s | ( | constraint_handler_t | handler | ) |
The set_mem_constraint_handler_s function sets the runtime-constraint handler to be handler.
The runtime-constraint handler is the function to be called when a library function detects a runtime-constraint order:
EXTERN errno_t _memcpy_s_chk | ( | void *restrict | dest, |
rsize_t | dmax, | ||
const void *restrict | src, | ||
rsize_t | slen, | ||
const size_t | destbos, | ||
const size_t | srcbos | ||
) |
EXTERN errno_t _memmove_s_chk | ( | void * | dest, |
rsize_t | dmax, | ||
const void * | src, | ||
rsize_t | slen, | ||
const size_t | destbos, | ||
const size_t | srcbos | ||
) |
EXTERN errno_t _memset_s_chk | ( | void * | dest, |
rsize_t | dmax, | ||
int | value, | ||
rsize_t | n, | ||
const size_t | destbos | ||
) | && |
EXTERN errno_t _memset16_s_chk | ( | uint16_t * | dest, |
rsize_t | dmax, | ||
uint16_t | value, | ||
rsize_t | n, | ||
const size_t | destbos | ||
) | && |
EXTERN errno_t _memset32_s_chk | ( | uint32_t * | dest, |
rsize_t | dmax, | ||
uint32_t | value, | ||
rsize_t | n, | ||
const size_t | destbos | ||
) | && |
EXTERN errno_t _memcmp_s_chk | ( | const void * | dest, |
rsize_t | dmax, | ||
const void * | src, | ||
rsize_t | slen, | ||
int * | diff, | ||
const size_t | destbos, | ||
const size_t | srcbos | ||
) |
EXTERN errno_t _memcmp16_s_chk | ( | const uint16_t * | dest, |
rsize_t | dlen, | ||
const uint16_t * | src, | ||
rsize_t | slen, | ||
int * | diff, | ||
const size_t | destbos, | ||
const size_t | srcbos | ||
) |
EXTERN errno_t _memcmp32_s_chk | ( | const uint32_t * | dest, |
rsize_t | dlen, | ||
const uint32_t * | src, | ||
rsize_t | slen, | ||
int * | diff, | ||
const size_t | destbos, | ||
const size_t | srcbos | ||
) |
EXTERN errno_t _memcpy16_s_chk | ( | uint16_t * | dest, |
rsize_t | dmax, | ||
const uint16_t * | src, | ||
rsize_t | slen, | ||
const size_t | destbos, | ||
const size_t | srcbos | ||
) |
EXTERN errno_t _memcpy32_s_chk | ( | uint32_t * | dest, |
rsize_t | dmax, | ||
const uint32_t * | src, | ||
rsize_t | slen, | ||
const size_t | destbos, | ||
const size_t | srcbos | ||
) |
EXTERN errno_t _memmove16_s_chk | ( | uint16_t * | dest, |
rsize_t | dmax, | ||
const uint16_t * | src, | ||
rsize_t | slen, | ||
const size_t | destbos, | ||
const size_t | srcbos | ||
) |
EXTERN errno_t _memmove32_s_chk | ( | uint32_t * | dest, |
rsize_t | dmax, | ||
const uint32_t * | src, | ||
rsize_t | slen, | ||
const size_t | destbos, | ||
const size_t | srcbos | ||
) |
EXTERN errno_t _memchr_s_chk | ( | const void *restrict | dest, |
rsize_t | dmax, | ||
const int | ch, | ||
void ** | result, | ||
const size_t | destbos | ||
) |
EXTERN errno_t _memrchr_s_chk | ( | const void *restrict | dest, |
rsize_t | dmax, | ||
const int | ch, | ||
void ** | result, | ||
const size_t | destbos | ||
) |
EXTERN errno_t BOS_NULL | ( | result | ) |
EXTERN int _timingsafe_bcmp_chk | ( | const void * | b1, |
const void * | b2, | ||
size_t | n, | ||
const size_t | destbos, | ||
const size_t | srcbos | ||
) |
EXTERN int n BOS_OVR2 | ( | b2 | , |
n | |||
) |
EXTERN int _timingsafe_memcmp_chk | ( | const void * | b1, |
const void * | b2, | ||
size_t | len, | ||
const size_t | destbos, | ||
const size_t | srcbos | ||
) |
EXTERN errno_t _memccpy_s_chk | ( | void * | dest, |
rsize_t | dmax, | ||
const void * | src, | ||
int | c, | ||
rsize_t | n, | ||
const size_t | destbos, | ||
const size_t | srcbos | ||
) |
EXTERN errno_t n VAL_OVR2 | ( | c | , |
255 | |||
) |
EXTERN errno_t _wmemcpy_s_chk | ( | wchar_t *restrict | dest, |
rsize_t | dmax, | ||
const wchar_t *restrict | src, | ||
rsize_t | smax, | ||
const size_t | destbos, | ||
const size_t | srcbos | ||
) |
EXTERN errno_t _wmemmove_s_chk | ( | wchar_t * | dest, |
rsize_t | dmax, | ||
const wchar_t * | src, | ||
rsize_t | smax, | ||
const size_t | destbos, | ||
const size_t | srcbos | ||
) |
EXTERN errno_t _wmemcmp_s_chk | ( | const wchar_t * | dest, |
rsize_t | dmax, | ||
const wchar_t * | src, | ||
rsize_t | slen, | ||
int * | diff, | ||
const size_t | destbos, | ||
const size_t | srcbos | ||
) |
EXTERN errno_t n dmax |
EXTERN errno_t dlen |