$darkmode
Implementation of utility functions. More...
Functions | |
| int | safe_snprintf (char *buf, size_t buf_size, const char *format,...) |
| Safe wrapper around vsnprintf to format strings with bounds checking. More... | |
| void * | safe_calloc (size_t num, size_t size) |
| calloc wrapper with zero-size check. More... | |
| bool | safe_memcpy (void *dest, size_t dest_size, const void *src, size_t count) |
| memcpy wrapper with bounds checking. More... | |
| bool | safe_memset (void *dest, size_t dest_size, int value, size_t count) |
| memset wrapper with bounds checking. More... | |
| void | safe_strncpy (char *dest, size_t dest_size, const char *src, size_t src_size) |
| Safe wrapper around strncpy to ensure null-termination. More... | |
| void | safe_strncat (char *dest, size_t dest_size, const char *src) |
| Safe wrapper around strncat to ensure bounds safety. More... | |
| bool | is_safe_filename (const char *filename) |
| Validates a filename to prevent path traversal and shell injection. More... | |
| bool | is_safe_relative_path (const char *path) |
| Validates a relative path to prevent arbitrary file access. More... | |
| void * | utils_buffer_offset (size_t offset) |
| Helper to securely cast an integer offset to a pointer, often used for VBO/EBO byte offsets. More... | |
Implementation of utility functions.
| bool is_safe_filename | ( | const char * | filename | ) |
Validates a filename to prevent path traversal and shell injection.
Rejects strings containing path separators ('/', '\') or directory traversal sequences ("..") or current directory (".").
| filename | The filename to check. |
| bool is_safe_relative_path | ( | const char * | path | ) |
Validates a relative path to prevent arbitrary file access.
Rejects absolute paths, parent directory traversal (".."), and platform-specific path features like backslashes or drive letters.
| path | The relative path to check. |
| void* safe_calloc | ( | size_t | num, |
| size_t | size | ||
| ) |
calloc wrapper with zero-size check.
| bool safe_memcpy | ( | void * | dest, |
| size_t | dest_size, | ||
| const void * | src, | ||
| size_t | count | ||
| ) |
memcpy wrapper with bounds checking.
| bool safe_memset | ( | void * | dest, |
| size_t | dest_size, | ||
| int | value, | ||
| size_t | count | ||
| ) |
memset wrapper with bounds checking.
| int safe_snprintf | ( | char * | buf, |
| size_t | buf_size, | ||
| const char * | format, | ||
| ... | |||
| ) |
Safe wrapper around vsnprintf to format strings with bounds checking.
| buf | Destination buffer. |
| buf_size | Buffer capacity. |
| format | Printf-style format string. |
| void safe_strncat | ( | char * | dest, |
| size_t | dest_size, | ||
| const char * | src | ||
| ) |
Safe wrapper around strncat to ensure bounds safety.
| dest | Destination buffer. |
| dest_size | Total size of destination buffer. |
| src | Source string. |
| void safe_strncpy | ( | char * | dest, |
| size_t | dest_size, | ||
| const char * | src, | ||
| size_t | src_size | ||
| ) |
Safe wrapper around strncpy to ensure null-termination.
| dest | Destination buffer. |
| dest_size | Size of destination buffer. |
| src | Source string. |
| src_size | Max characters to copy (or just use sizeof(dest)). |
| void* utils_buffer_offset | ( | size_t | offset | ) |
Helper to securely cast an integer offset to a pointer, often used for VBO/EBO byte offsets.
| offset | The byte offset to cast. |