|
OpenVPN
|
#include "syshead.h"#include "common.h"#include "buffer.h"#include "error.h"#include "mtu.h"#include "misc.h"#include "memdbg.h"#include <wchar.h>

Go to the source code of this file.
Macros | |
| #define | buf_debug_line(buf) 0 |
| #define | buf_debug_file(buf) "[UNDEF]" |
Functions | |
| size_t | array_mult_safe (const size_t m1, const size_t m2, const size_t extra) |
| Safely compute the product of two sizes plus an extra amount. | |
| void | buf_size_error (const size_t size) |
| Report a buffer size error and abort. | |
| struct buffer | alloc_buf (size_t size) |
| Allocate a buffer of the given size. | |
| struct buffer | alloc_buf_gc (size_t size, struct gc_arena *gc) |
| Allocate a buffer of the given size under garbage collection. | |
| struct buffer | clone_buf (const struct buffer *buf) |
| Duplicate a buffer, including its content. | |
| void | buf_clear (struct buffer *buf) |
| Zeroise and reset a buffer. | |
| bool | buf_assign (struct buffer *dest, const struct buffer *src) |
| Assign the content of one buffer to another. | |
| void | free_buf (struct buffer *buf) |
| Free the memory allocated for a buffer. | |
| static void | free_buf_gc (struct buffer *buf, struct gc_arena *gc) |
| struct buffer | buf_sub (struct buffer *buf, int size, bool prepend) |
| Return a sub-buffer of another buffer. | |
| bool | buf_printf (struct buffer *buf, const char *format,...) |
| printf-style append to a buffer with overflow check. | |
| bool | buf_puts (struct buffer *buf, const char *str) |
| Append a string to a buffer with overflow check. | |
| void | buf_catrunc (struct buffer *buf, const char *str) |
Append a string to the physical end of a buffer that was truncated by buf_printf(). | |
| bool | buffer_write_file (const char *filename, const struct buffer *buf) |
| Write buffer contents to file. | |
| void * | gc_malloc (size_t size, bool clear, struct gc_arena *a) |
| Allocate memory and, optionally, zero it. | |
| void * | gc_realloc (void *ptr, size_t size, struct gc_arena *a) |
| allows to realloc a pointer previously allocated by gc_malloc or gc_realloc | |
| void | x_gc_free (struct gc_arena *a) |
| Free all plain allocations in a garbage collection arena. | |
| void | x_gc_freespecial (struct gc_arena *a) |
| Free all specially-allocated entries in a garbage collection arena. | |
| void | gc_addspecial (void *addr, void(*free_function)(void *), struct gc_arena *a) |
| Register an address with a custom free function in a garbage collection arena. | |
| void | gc_transfer (struct gc_arena *dest, struct gc_arena *src) |
| Move all allocations from one garbage collection arena to another. | |
| char * | format_hex_ex (const uint8_t *data, size_t size, size_t maxoutput, unsigned int space_break_flags, const char *separator, struct gc_arena *gc) |
| Format a binary buffer as a hex string. | |
| void | buf_rmtail (struct buffer *buf, uint8_t remove) |
| Remove all occurrences of a specific byte from the end of a buffer. | |
| void | buf_null_terminate (struct buffer *buf) |
| Force a null terminator at the end of the buffer content. | |
| void | buf_chomp (struct buffer *buf) |
| Remove trailing newline and carriage-return characters from a buffer. | |
| const char * | skip_leading_whitespace (const char *str) |
| Return a pointer past any leading whitespace in a string. | |
| void | string_null_terminate (char *str, int len, int capacity) |
| Null-terminate a fixed-length string buffer. | |
| void | chomp (char *str) |
| Remove trailing newline and carriage-return characters from a string. | |
| void | rm_trailing_chars (char *str, const char *what_to_delete) |
| Remove all trailing characters that appear in a given set. | |
| char * | string_alloc (const char *str, struct gc_arena *gc) |
| Duplicate a string, allocating memory under garbage collection. | |
| void | string_clear (char *str) |
| Securely clear a null-terminated string. | |
| int | string_array_len (const char **array) |
| Return the number of elements in a NULL-terminated array of strings. | |
| char * | print_argv (const char **p, struct gc_arena *gc, const unsigned int flags) |
| Format a NULL-terminated argument vector as a single string. | |
| struct buffer | string_alloc_buf (const char *str, struct gc_arena *gc) |
| Allocate a buffer containing a copy of the given string. | |
| bool | buf_string_match_head_str (const struct buffer *src, const char *match) |
Return true if the head of src matches the string match. | |
| bool | buf_string_compare_advance (struct buffer *src, const char *match) |
Compare the head of src with match and advance past it if equal. | |
| int | buf_substring_len (const struct buffer *buf, int delim) |
| Return the number of bytes in a buffer up to and including a delimiter. | |
| bool | buf_parse (struct buffer *buf, const int delim, char *line, const int size) |
| Extract the next token from a buffer, delimited by a given character. | |
| const char * | np (const char *str) |
| Return a printable representation of a string that might be NULL. | |
| bool | char_class (const unsigned char c, const unsigned int flags) |
| Test whether a character belongs to one or more character classes. | |
| static bool | char_inc_exc (const char c, const unsigned int inclusive, const unsigned int exclusive) |
| bool | string_class (const char *str, const unsigned int inclusive, const unsigned int exclusive) |
| Test whether all characters in a string satisfy a character class filter. | |
| bool | string_mod (char *str, const unsigned int inclusive, const unsigned int exclusive, const char replace) |
| Modifies a string in place by replacing certain classes of characters of it with a specified character. | |
| bool | string_check_buf (const struct buffer *buf, const unsigned int inclusive, const unsigned int exclusive) |
| Check a buffer if it only consists of allowed characters. | |
| const char * | string_mod_const (const char *str, const unsigned int inclusive, const unsigned int exclusive, const char replace, struct gc_arena *gc) |
| Returns a copy of a string with certain classes of characters of it replaced with a specified character. | |
| void | string_replace_leading (char *str, const char match, const char replace) |
| Replace all leading occurrences of a character in a string. | |
| bool | string_defined_equal (const char *s1, const char *s2) |
| char * | string_substitute (const char *src, char from, char to, struct gc_arena *gc) |
| bool | checked_snprintf (char *str, size_t size, const char *format,...) |
| Like snprintf() but returns an boolean. | |
| struct buffer_list * | buffer_list_new (void) |
Allocate an empty buffer list of capacity max_size. | |
| void | buffer_list_free (struct buffer_list *ol) |
| Frees a buffer list and all the buffers in it. | |
| bool | buffer_list_defined (const struct buffer_list *ol) |
| Checks if the list is valid and non-empty. | |
| void | buffer_list_reset (struct buffer_list *ol) |
Empty the list ol and frees all the contained buffers. | |
| void | buffer_list_push (struct buffer_list *ol, const char *str) |
Allocates and appends a new buffer containing str as data to ol. | |
| struct buffer_entry * | buffer_list_push_data (struct buffer_list *ol, const void *data, size_t size) |
Allocates and appends a new buffer containing data of length size. | |
| struct buffer * | buffer_list_peek (struct buffer_list *ol) |
| Retrieve the head buffer. | |
| void | buffer_list_aggregate_separator (struct buffer_list *bl, const size_t max_len, const char *sep) |
Aggregates as many buffers as possible from bl in a new buffer of maximum length max_len . | |
| void | buffer_list_aggregate (struct buffer_list *bl, const size_t max) |
Aggregates as many buffers as possible from bl in a new buffer of maximum length max_len . | |
| void | buffer_list_pop (struct buffer_list *ol) |
| Remove and free the head buffer of the list. | |
| void | buffer_list_advance (struct buffer_list *ol, ssize_t n) |
Advance past n bytes in the head buffer, popping it if it becomes empty. | |
| struct buffer_list * | buffer_list_file (const char *fn, int max_line_len) |
| Read a file into a buffer list, one buffer per line. | |
| struct buffer | buffer_read_from_file (const char *filename, struct gc_arena *gc) |
| buffer_read_from_file - copy the content of a file into a buffer | |
| char * | buf_extract_field (struct buffer *buf, char sep, struct gc_arena *gc) |
Extract a field from buf that ends with the sep character. | |
| struct buffer alloc_buf | ( | size_t | size | ) |
Allocate a buffer of the given size.
Calls out_of_memory() if the allocation fails. The caller is responsible for freeing the memory.
| size | Number of bytes to allocate. |
size. Definition at line 60 of file buffer.c.
References buf_size_error(), buf_size_valid(), buffer::capacity, check_malloc_return(), CLEAR, buffer::data, and buffer::len.
Referenced by alloc_buf_sock_tun(), auth_token_init_secret(), buffer_list_aggregate_separator(), buffer_list_push_data(), check_inline_file(), command_line_new(), fragment_frame_init(), fragment_list_buf_init(), init_context_buffers(), init_tas_auth(), init_tas_crypt(), key_state_init(), management_query_cert(), management_query_pk_sig(), mutate_ncp_cipher_list(), openvpn_PRF(), options_string(), read_inline_file(), reliable_init(), send_line_crlf(), status_open(), stream_buf_init(), test_generate_reset_packet_plain(), test_incoming_push_continuation_route_accumulation(), test_incoming_push_message_1(), test_incoming_push_message_bad_format(), test_incoming_push_message_basic(), test_incoming_push_message_error1(), test_incoming_push_message_error2(), test_incoming_push_message_mix(), test_incoming_push_message_mix2(), test_incoming_push_message_not_updatable_option(), test_mbuf_add_remove(), test_parse_ack(), test_tls_crypt_setup(), test_tls_decrypt_lite_auth(), test_tls_decrypt_lite_crypt(), test_tls_decrypt_lite_none(), test_verify_hmac_none(), test_verify_hmac_none_out_of_range_ack(), test_verify_hmac_tls_auth(), tls_crypt_v2_extract_client_key(), tls_crypt_v2_init_client_key(), tls_session_generate_dynamic_tls_crypt_key(), tls_session_init(), tun_show_debug(), and tuntap_dhcp_mask().
Allocate a buffer of the given size under garbage collection.
The allocated memory is registered with gc so that it is freed when gc_free() is called on the arena. Calls out_of_memory() if the allocation fails.
| size | Number of bytes to allocate. |
| gc | Garbage collection arena to register the allocation with. |
size. Definition at line 77 of file buffer.c.
References buf_size_error(), buf_size_valid(), buffer::capacity, CLEAR, buffer::data, gc, gc_malloc(), and buffer::len.
Referenced by __wrap_buffer_read_from_file(), add_option(), buffer_read_from_file(), ce_management_query_proxy(), ce_management_query_remote(), check_incoming_control_channel(), construct_name_value(), create_client_key_input(), create_metadata_days_ago(), crypto_pem_encode(), dco_version_string(), do_data_channel_round_trip(), do_init_frame_tls(), encrypt_one_packet(), extract_command_buffer(), forge_msg(), fork_dhcp_action(), fork_register_dns_action(), format_common_name(), format_hex_ex(), format_ip_addr_string(), format_route_entry(), frame_print(), generate_auth_token(), get_device_guid(), get_unspecified_device_guid(), get_user_pass_cr(), hostname_randomize(), ifconfig_options_string(), ifconfig_pool_read(), ipset2ascii_all(), link_socket_connection_initiated(), log_entry_print(), management_callback_send_cc_message(), management_hold(), management_query_multiline(), management_query_user_pass(), mroute_addr_print_ex(), mroute_helper_regenerate(), msg_flags_string(), multi_instance_string(), ncp_expanded_ciphers(), netsh_get_id(), options_string_compat_lzo(), options_string_version(), options_warning_safe_ml(), ovpn_expand_label(), p2p_mode_ncp(), packet_id_net_print(), packet_id_persist_print(), platform_gen_path(), plugin_mask_string(), prepare_push_reply(), prepend_dir(), print_argv(), print_default_gateway(), print_in_port_t(), print_key_id(), print_link_socket_actual_ex(), print_netmask(), print_opt_route(), print_opt_route_gateway(), print_opt_route_gateway_dhcp(), print_opt_topology(), print_sockaddr_ex(), print_str_int(), proto2ascii_all(), protocol_dump(), push_peer_info(), read_control_auth(), reliable_ack_print(), send_auth_failed(), send_auth_pending_messages(), send_push_reply(), send_push_reply_auth_token(), server_pushed_info(), setenv_format_indexed_name(), setenv_route(), setenv_route_addr(), setenv_route_ipv6(), socket_stat(), strerror_win32(), system_error_message(), tap_win_getinfo(), test_buffer_chomp(), test_buffer_extract_field(), test_buffer_free_gc_one(), test_buffer_free_gc_two(), test_buffer_null_terminate(), test_buffer_parse(), test_buffer_printf_catrunc(), test_character_string_mod_buf(), test_crypto(), test_data_channel_known_vectors_run(), test_extract_control_message(), test_load_certificate_and_key_uri(), test_packet_id_write_epoch(), test_tls_crypt_v2_setup(), test_write_dhcp_search_str(), time_string(), tls_crypt_v2_wrap_client_key(), tls_crypt_v2_wrap_unwrap_dst_too_small(), tls_crypt_v2_wrap_unwrap_max_metadata(), tls_crypt_v2_wrap_unwrap_no_metadata(), tls_crypt_v2_write_client_key_file(), tun_stat(), tv_string(), username_password_as_base64(), verify_cert(), wide_cmd_line(), win32_version_string(), window_title_generate(), write_key_file(), write_outgoing_tls_ciphertext(), x509_get_sha1_fingerprint(), and x509_get_sha256_fingerprint().
| size_t array_mult_safe | ( | const size_t | m1, |
| const size_t | m2, | ||
| const size_t | extra | ||
| ) |
Safely compute the product of two sizes plus an extra amount.
Each of m1, m2, and extra, as well as the final result, are checked against ALLOC_SIZE_MAX. If any value exceeds the limit the function calls msg(M_FATAL) and does not return.
| m1 | First multiplicand. |
| m2 | Second multiplicand. |
| extra | Value to add to the product. |
m1 * m2 + extra. Definition at line 40 of file buffer.c.
References ALLOC_SIZE_MAX, M_FATAL, msg, and unlikely.
Assign the content of one buffer to another.
Copies the content of src into dest. The destination buffer must already be allocated with sufficient capacity.
| dest | Destination buffer to write into. |
| src | Source buffer to read from. |
dest has insufficient capacity. Definition at line 159 of file buffer.c.
References BLENZ, buf_init, buf_write(), CBPTR, buffer::len, and buffer::offset.
Referenced by buffer_turnover().
| void buf_catrunc | ( | struct buffer * | buf, |
| const char * | str | ||
| ) |
Append a string to the physical end of a buffer that was truncated by buf_printf().
If the buffer's forward capacity is one byte or less (i.e. it is full), str is written at the very end of the allocated memory to act as a truncation marker, provided it fits within the total buffer capacity. This is used to append a "[more...]" suffix after hex-dump truncation.
| buf | The buffer to append the truncation marker to. |
| str | The null-terminated marker string to write. |
Definition at line 273 of file buffer.c.
References buf_forward_capacity(), buf_forward_capacity_total(), buf_size_valid(), buffer::capacity, buffer::data, and buffer::len.
Referenced by format_hex_ex(), and test_buffer_printf_catrunc().
| void buf_chomp | ( | struct buffer * | buf | ) |
Remove trailing newline and carriage-return characters from a buffer.
| buf | The buffer to chomp. |
Definition at line 522 of file buffer.c.
References BLAST, buf_inc_len(), buf_null_terminate(), CC_CRLF, CC_NULL, char_class(), and buffer::len.
Referenced by command_line_get(), extract_command_buffer(), key_state_check_auth_pending_file(), and test_buffer_chomp().
| void buf_clear | ( | struct buffer * | buf | ) |
Zeroise and reset a buffer.
Sets all allocated memory to zero and resets offset and len to zero, but does not free the underlying memory.
| buf | The buffer to clear. |
Definition at line 148 of file buffer.c.
References buffer::capacity, buffer::data, buffer::len, buffer::offset, and secure_memzero().
Referenced by command_line_add(), command_line_next(), command_line_reset(), do_close_free_key_schedule(), in_extra_dispatch(), key_method_2_read(), openvpn_PRF(), read_control_auth(), read_inline_file(), read_key_file(), read_pem_key_file(), test_write_dhcp_search_str(), tls_crypt_fail_msg_too_long(), tls_crypt_fail_replay(), tls_crypt_ignore_replay(), tls_crypt_loopback_max_len(), tls_crypt_loopback_zero_len(), tls_crypt_v2_unwrap_client_key(), tls_crypt_v2_write_client_key_file(), tls_print_deferred_options_results(), write_key_file(), and write_pem_key_file().
Extract a field from buf that ends with the sep character.
The returned string is allocated in the gc_arena. If the separator character is not found, the function returns the nullptr.
The buffer is also forwarded to the point after the separator character.
Definition at line 1389 of file buffer.c.
References buf_advance(), buf_len(), buf_valid(), CBPTR, gc, gc_malloc(), and buffer::len.
Referenced by test_buffer_extract_field().
| void buf_null_terminate | ( | struct buffer * | buf | ) |
Force a null terminator at the end of the buffer content.
If there is free capacity, a '\0' byte is appended. If the buffer is full, the last content byte is overwritten with '\0' (i.e. the last character is truncated to make room). The function has no effect on an empty or invalid buffer.
| buf | The buffer to null-terminate. |
Definition at line 501 of file buffer.c.
References BLAST, buf_inc_len(), buf_safe(), buf_write_u8(), and buffer::len.
Referenced by buf_chomp(), buffer_read_from_file(), mutate_ncp_cipher_list(), status_read(), test_buffer_null_terminate(), and tls_crypt_v2_write_client_key_file().
| bool buf_parse | ( | struct buffer * | buf, |
| const int | delim, | ||
| char * | line, | ||
| const int | size | ||
| ) |
Extract the next token from a buffer, delimited by a given character.
Reads bytes from buf one at a time until delim or end-of-buffer is encountered. The token (without the delimiter) is written into line, which is always null-terminated. The delimiter byte is consumed from buf but not included in line.
| buf | Source buffer to parse. The consumed portion is advanced. |
| delim | Delimiter character. |
| line | Output buffer for the extracted token. |
| size | Size of line in bytes (must be > 0). |
line was truncated). Definition at line 775 of file buffer.c.
References ASSERT, buf_advance(), buf_peek_u8(), and buffer::len.
Referenced by apply_push_options(), get_user_pass_cr(), ifconfig_pool_read(), in_src_get(), make_inline_array(), man_kill(), man_output_peer_info_env(), options_warning_extract_parm1(), options_warning_safe_scan1(), options_warning_safe_scan2(), output_peer_info_env(), parse_auth_challenge(), parse_auth_pending_keywords(), push_update_digest(), read_config_string(), and test_buffer_parse().
| bool buf_printf | ( | struct buffer * | buf, |
| const char * | format, | ||
| ... | |||
| ) |
printf-style append to a buffer with overflow check.
Formats a string and appends it to buf. Due to the use of vsnprintf(), one byte of forward capacity is reserved for a null terminator, so at most buf_forward_capacity(buf) - 1 bytes of formatted output are written.
| buf | The buffer to append to. |
| format | printf-style format string. |
| ... | Format arguments. |
Definition at line 226 of file buffer.c.
References BEND, buf_defined(), buf_forward_capacity(), buffer::capacity, buffer::data, and buffer::len.
Referenced by add_delim_if_non_empty(), add_option(), ce_management_query_proxy(), ce_management_query_remote(), check_inline_file(), construct_name_value(), dco_version_string(), forge_msg(), fork_dhcp_action(), fork_register_dns_action(), format_common_name(), format_hex_ex(), format_ip_addr_string(), format_route_entry(), frame_print(), get_device_guid(), get_unspecified_device_guid(), get_user_pass_cr(), hostname_randomize(), ifconfig_options_string(), ipset2ascii_all(), link_socket_connection_initiated(), log_entry_print(), management_callback_send_cc_message(), management_hold(), management_query_multiline(), management_query_user_pass(), mroute_addr_print_ex(), mroute_helper_regenerate(), msg_flags_string(), multi_instance_string(), ncp_expanded_ciphers(), options_string(), options_string_compat_lzo(), options_warning_safe_ml(), p2p_mode_ncp(), packet_id_net_print(), packet_id_persist_print(), platform_gen_path(), plugin_mask_string(), prepare_push_reply(), prepend_dir(), print_argv(), print_default_gateway(), print_in_port_t(), print_key_id(), print_link_socket_actual_ex(), print_netmask(), print_opt_route(), print_opt_route_gateway(), print_opt_route_gateway_dhcp(), print_opt_topology(), print_sockaddr_ex(), print_str_int(), proto2ascii_all(), protocol_dump(), push_peer_info(), push_peer_info_peerid(), read_inline_file(), reliable_ack_print(), send_auth_failed(), send_auth_pending_messages(), send_push_options(), send_push_reply(), send_push_reply_auth_token(), server_pushed_info(), setenv_format_indexed_name(), setenv_route(), setenv_route_addr(), setenv_route_ipv6(), setenv_str_safe(), socket_stat(), strerror_win32(), system_error_message(), test_buffer_printf_catrunc(), test_load_certificate_and_key_uri(), time_string(), tls_print_deferred_options_results(), tun_stat(), tv_string(), username_password_as_base64(), verify_cert(), wide_cmd_line(), win32_print_arch(), win32_version_string(), window_title_generate(), and write_key_file().
| bool buf_puts | ( | struct buffer * | buf, |
| const char * | str | ||
| ) |
Append a string to a buffer with overflow check.
| buf | The buffer to append to. |
| str | The null-terminated string to append. |
Definition at line 253 of file buffer.c.
References BEND, buf_forward_capacity(), buffer::capacity, buffer::data, buffer::len, and strncpynt().
Referenced by mutate_ncp_cipher_list(), and print_sockaddr_ex().
| void buf_rmtail | ( | struct buffer * | buf, |
| uint8_t | remove | ||
| ) |
Remove all occurrences of a specific byte from the end of a buffer.
| buf | The buffer to modify. |
| remove | The byte value to strip from the tail. |
Definition at line 486 of file buffer.c.
References BLAST, and buffer::len.
| void buf_size_error | ( | const size_t | size | ) |
Report a buffer size error and abort.
Called when a requested buffer size exceeds BUF_SIZE_MAX or is otherwise invalid. Calls msg(M_FATAL) and does not return.
| size | The invalid size that was requested. |
Definition at line 54 of file buffer.c.
Referenced by alloc_buf(), alloc_buf_gc(), buf_set_read(), and buf_set_write().
| bool buf_string_compare_advance | ( | struct buffer * | src, |
| const char * | match | ||
| ) |
Compare the head of src with match and advance past it if equal.
If the buffer starts with match, the matched bytes are consumed from src. NOT constant time. Do not use when comparing HMACs.
| src | Buffer to compare and advance. |
| match | Null-terminated string to compare against. |
match (and was advanced). Definition at line 739 of file buffer.c.
References buf_advance(), buf_string_match_head_str(), and buffer::len.
Referenced by process_incoming_push_msg(), receive_auth_failed(), and send_single_push_update().
| bool buf_string_match_head_str | ( | const struct buffer * | src, |
| const char * | match | ||
| ) |
Return true if the head of src matches the string match.
Compares the first strlen(match) bytes of src content with match. NOT constant time. Do not use when comparing HMACs.
| src | Buffer whose head is compared. |
| match | Null-terminated string to compare against. |
match. Definition at line 728 of file buffer.c.
References buf_size_valid(), CBPTR, and buffer::len.
Referenced by buf_string_compare_advance(), parse_incoming_control_channel_command(), and receive_auth_failed().
Return a sub-buffer of another buffer.
Either allocates size bytes from the front or back of buf, shrinking buf accordingly, and returns a buffer pointing into the same memory.
| buf | Source buffer to carve the sub-buffer from. |
| size | Number of bytes to include in the sub-buffer. |
| prepend | If true, take bytes from the front of buf (prepend space); if false, take bytes from the end (append space). |
buf has insufficient capacity. Definition at line 207 of file buffer.c.
References buf_prepend(), buf_write_alloc(), CLEAR, buffer::data, and buffer::len.
Referenced by reliable_ack_write(), and socks_process_outgoing_udp().
| int buf_substring_len | ( | const struct buffer * | buf, |
| int | delim | ||
| ) |
Return the number of bytes in a buffer up to and including a delimiter.
The count includes the delimiter byte, so it can be passed straight to buf_copy_excess() to split off a complete record, keeping the delimiter with it.
| buf | The buffer to scan. |
| delim | Delimiter byte to search for. |
delim, or -1 if the buffer contains no delim. Definition at line 753 of file buffer.c.
References buf_read_u8(), and buffer::len.
Referenced by command_line_get().
| void buffer_list_advance | ( | struct buffer_list * | ol, |
| ssize_t | n | ||
| ) |
Advance past n bytes in the head buffer, popping it if it becomes empty.
n must not exceed the length of the head buffer; passing a larger value triggers an assertion failure.
| ol | The list whose head buffer is to be advanced. |
| n | Number of bytes to skip in the head buffer. |
Definition at line 1319 of file buffer.c.
References ASSERT, BLEN, buf_advance(), buffer_list_pop(), buffer_list::head, and buffer::len.
Referenced by man_write().
| void buffer_list_aggregate | ( | struct buffer_list * | bl, |
| const size_t | max | ||
| ) |
Aggregates as many buffers as possible from bl in a new buffer of maximum length max_len .
All the aggregated buffers are removed from the list and replaced by the new one, followed by any additional (non-aggregated) data.
| bl | the list of buffer to aggregate |
| max | the maximum length of the aggregated buffer |
Definition at line 1296 of file buffer.c.
References buffer_list_aggregate_separator().
Referenced by in_extra_dispatch(), man_write(), and management_query_multiline_flatten().
| void buffer_list_aggregate_separator | ( | struct buffer_list * | bl, |
| const size_t | max_len, | ||
| const char * | sep | ||
| ) |
Aggregates as many buffers as possible from bl in a new buffer of maximum length max_len .
sep is written after each copied buffer (also after the last one). All the aggregated buffers are removed from the list and replaced by the new one, followed by any additional (non-aggregated) data. Nothing happens if max_len is not enough to aggregate at least 2 buffers.
| bl | the list of buffer to aggregate |
| max_len | the maximum length of the aggregated buffer |
| sep | the separator to put between buffers during aggregation |
Definition at line 1251 of file buffer.c.
References alloc_buf(), ALLOC_OBJ_CLEAR, BLENZ, buffer_entry::buf, buf_copy(), buf_write(), free_buf(), buffer_list::head, buffer::len, buffer_entry::next, buffer_list::size, and buffer_list::tail.
Referenced by buffer_list_aggregate(), management_query_multiline_flatten_newline(), test_buffer_list_aggregate_separator_all(), test_buffer_list_aggregate_separator_empty(), test_buffer_list_aggregate_separator_emptybuffers(), test_buffer_list_aggregate_separator_noop(), test_buffer_list_aggregate_separator_nosep(), test_buffer_list_aggregate_separator_two(), and test_buffer_list_aggregate_separator_zerolen().
| bool buffer_list_defined | ( | const struct buffer_list * | ol | ) |
Checks if the list is valid and non-empty.
| ol | the list to check |
ol is not NULL and contains at least one buffer Definition at line 1175 of file buffer.c.
References buffer_list::head, and buffer_list::size.
Referenced by buffer_list_pop(), man_update_io_state(), management_query_multiline_flatten(), and management_query_multiline_flatten_newline().
| struct buffer_list * buffer_list_file | ( | const char * | fn, |
| int | max_line_len | ||
| ) |
Read a file into a buffer list, one buffer per line.
Opens fn for reading and pushes each line into a newly allocated buffer list using fgets(). Lines longer than max_line_len - 1 bytes are split across multiple consecutive buffers.
| fn | Path to the file to read. |
| max_line_len | Maximum number of bytes (including null terminator) read per fgets() call. |
Definition at line 1333 of file buffer.c.
References buffer_list_new(), buffer_list_push(), and platform_fopen().
Referenced by key_state_check_auth_pending_file().
| void buffer_list_free | ( | struct buffer_list * | ol | ) |
Frees a buffer list and all the buffers in it.
| ol | the list to free |
Definition at line 1165 of file buffer.c.
References buffer_list_reset().
Referenced by in_extra_dispatch(), in_extra_reset(), key_state_check_auth_pending_file(), key_state_free(), man_connection_close(), management_client_auth(), management_query_multiline_flatten(), management_query_multiline_flatten_newline(), send_push_update(), set_cc_config(), and test_buffer_list_teardown().
| struct buffer_list * buffer_list_new | ( | void | ) |
Allocate an empty buffer list of capacity max_size.
Definition at line 1156 of file buffer.c.
References ALLOC_OBJ_CLEAR, and buffer_list::size.
Referenced by buffer_list_file(), in_extra_reset(), man_connection_init(), send_push_update(), test_buffer_list_setup(), and tls_send_payload().
| struct buffer * buffer_list_peek | ( | struct buffer_list * | ol | ) |
Retrieve the head buffer.
| ol | the list to retrieve the buffer from |
Definition at line 1238 of file buffer.c.
References buffer::len.
Referenced by flush_payload_buffer(), in_extra_dispatch(), man_write(), management_query_multiline_flatten(), management_query_multiline_flatten_newline(), test_buffer_list_aggregate_separator_all(), test_buffer_list_aggregate_separator_emptybuffers(), test_buffer_list_aggregate_separator_noop(), test_buffer_list_aggregate_separator_nosep(), test_buffer_list_aggregate_separator_two(), and test_buffer_list_aggregate_separator_zerolen().
| void buffer_list_pop | ( | struct buffer_list * | ol | ) |
Remove and free the head buffer of the list.
Does nothing if ol is NULL or empty.
| ol | The list to pop from. |
Definition at line 1302 of file buffer.c.
References buffer_entry::buf, buffer_list_defined(), free_buf(), buffer_list::head, buffer_entry::next, buffer_list::size, and buffer_list::tail.
Referenced by buffer_list_advance(), and flush_payload_buffer().
| void buffer_list_push | ( | struct buffer_list * | ol, |
| const char * | str | ||
| ) |
Allocates and appends a new buffer containing str as data to ol.
| ol | the list to append the new buffer to |
| str | the string to copy into the new buffer |
Definition at line 1196 of file buffer.c.
References buffer_entry::buf, buffer_list_push_data(), and buffer::len.
Referenced by buffer_list_file(), man_output_list_push_str(), man_read(), message_splitter(), and test_buffer_list_setup().
| struct buffer_entry * buffer_list_push_data | ( | struct buffer_list * | ol, |
| const void * | data, | ||
| size_t | size | ||
| ) |
Allocates and appends a new buffer containing data of length size.
| ol | the list to append the new buffer to |
| data | the data to copy into the new buffer |
| size | the length of data to copy into the buffer |
Definition at line 1210 of file buffer.c.
References alloc_buf(), ALLOC_OBJ_CLEAR, ASSERT, buffer_entry::buf, buffer::data, buffer_list::head, buffer::len, buffer_entry::next, buffer_list::size, and buffer_list::tail.
Referenced by buffer_list_push(), test_buffer_list_setup(), and tls_send_payload().
| void buffer_list_reset | ( | struct buffer_list * | ol | ) |
Empty the list ol and frees all the contained buffers.
| ol | the list to reset |
Definition at line 1181 of file buffer.c.
References buffer_entry::buf, free_buf(), buffer_list::head, buffer_entry::next, buffer_list::size, and buffer_list::tail.
Referenced by buffer_list_free(), man_new_connection_post(), man_read(), and man_reset_client_socket().
buffer_read_from_file - copy the content of a file into a buffer
| filename | path to the file to read |
| gc | the garbage collector to use when allocating the buffer. It is passed to alloc_buf_gc() and therefore can be NULL. |
Definition at line 1356 of file buffer.c.
References alloc_buf_gc(), ASSERT, BPTR, buf_inc_len(), buf_null_terminate(), cleanup(), free_buf_gc(), gc, buffer::len, platform_fopen(), and platform_stat().
Referenced by connection_entry_preload_key(), crypto_pem_encode_certificate(), key_state_check_auth_failed_message_file(), read_key_file(), and read_pem_key_file().
| bool buffer_write_file | ( | const char * | filename, |
| const struct buffer * | buf | ||
| ) |
Write buffer contents to file.
| filename | The filename to write the buffer to. |
| buf | The buffer to write to the file. |
Definition at line 286 of file buffer.c.
References BLEN, CBPTR, cleanup(), buffer::len, M_ERRNO, msg, platform_open(), and write.
Referenced by tls_crypt_v2_verify_metadata(), tls_crypt_v2_write_client_key_file(), write_key_file(), and write_pem_key_file().
| bool char_class | ( | const unsigned char | c, |
| const unsigned int | flags | ||
| ) |
Test whether a character belongs to one or more character classes.
| c | The character to test. |
| flags | Bitmask of CC_* character class flags. |
c matches any of the classes specified in flags. Definition at line 839 of file buffer.c.
References CC_ALNUM, CC_ALPHA, CC_ANY, CC_ASCII, CC_ASTERISK, CC_BACKSLASH, CC_BLANK, CC_CNTRL, CC_COLON, CC_COMMA, CC_CR, CC_DASH, CC_DIGIT, CC_DOT, CC_DOUBLE_QUOTE, CC_EXCLAMATION, CC_GREATER_THAN, CC_LESS_THAN, CC_NEWLINE, CC_NULL, CC_PERCENT, CC_PIPE, CC_PRINT, CC_PUNCT, CC_QUESTION_MARK, CC_REVERSE_QUOTE, CC_SINGLE_QUOTE, CC_SLASH, CC_SPACE, CC_UNDERBAR, CC_XDIGIT, and buffer::len.
Referenced by buf_chomp(), char_inc_exc(), and command_line_add().
|
inlinestatic |
Definition at line 979 of file buffer.c.
References char_class(), and buffer::len.
Referenced by string_check_buf(), string_class(), and string_mod().
| bool checked_snprintf | ( | char * | str, |
| size_t | size, | ||
| const char * | format, | ||
| ... | |||
| ) |
Like snprintf() but returns an boolean.
To check the return value of snprintf() one needs to do multiple comparisons of the size parameter against the return value. Doesn't get prettier by them being different types with different signedness and size.
So this function allows to wrap all of that into one boolean return value.
Definition at line 1121 of file buffer.c.
References ASSERT, and buffer::len.
Referenced by append_cipher_to_ncp_list(), env_block(), establish_http_proxy_passthru(), get_panel_reg(), get_tap_reg(), platform_create_temp_file(), setenv_str_incr(), socks_username_password_auth(), test_checked_snprintf(), and verify_check_crl_dir().
| void chomp | ( | char * | str | ) |
Remove trailing newline and carriage-return characters from a string.
| str | The null-terminated string to chomp. |
Definition at line 584 of file buffer.c.
References buffer::len, and rm_trailing_chars().
Referenced by establish_http_proxy_passthru(), get_console_input(), get_console_input_win32(), get_proxy_authenticate(), get_user_pass_cr(), make_inline_array(), man_output_peer_info_env(), output_peer_info_env(), and status_printf().
Duplicate a buffer, including its content.
Allocates a new buffer with the same capacity as buf and copies its content. Calls out_of_memory() if the allocation fails.
| buf | The buffer to duplicate. |
buf. Definition at line 99 of file buffer.c.
References BLENZ, BPTR, buffer::capacity, CBPTR, check_malloc_return(), buffer::data, buffer::len, and buffer::offset.
Referenced by mbuf_alloc_buf(), and tls_pre_decrypt_lite().
| char * format_hex_ex | ( | const uint8_t * | data, |
| size_t | size, | ||
| size_t | maxoutput, | ||
| unsigned int | space_break_flags, | ||
| const char * | separator, | ||
| struct gc_arena * | gc | ||
| ) |
Format a binary buffer as a hex string.
| data | Pointer to the binary data to format. |
| size | Number of bytes to format. |
| maxoutput | Maximum number of output characters (0 = unlimited). If the output is truncated, a "[more...]" suffix is appended via buf_catrunc(). |
| space_break_flags | Lower 8 bits (FHE_SPACE_BREAK_MASK) give the number of bytes between separator insertions. Use FHE_CAPS to output upper-case hex digits. |
| separator | String to insert between groups of bytes. |
| gc | Garbage collection arena for the returned string. |
gc. Definition at line 452 of file buffer.c.
References alloc_buf_gc(), buf_catrunc(), buf_printf(), buffer::data, FHE_CAPS, FHE_SPACE_BREAK_MASK, gc, and buffer::len.
Referenced by backend_x509_get_serial_hex(), export_user_keying_material(), format_hex(), hostname_randomize(), mroute_addr_print_ex(), print_default_gateway(), push_peer_info(), read_key_file(), show_adapter(), show_settings(), test_buffer_format_hex_ex(), verify_cert(), verify_cert_set_env(), write_key_file(), and x509_setenv_track().
| void free_buf | ( | struct buffer * | buf | ) |
Free the memory allocated for a buffer.
Frees buf->data and resets the buffer to an undefined state.
| buf | The buffer whose memory is to be freed. |
Definition at line 169 of file buffer.c.
References CLEAR, and buffer::data.
Referenced by auth_token_init_secret(), buffer_list_aggregate_separator(), buffer_list_pop(), buffer_list_reset(), check_inline_file(), command_line_free(), do_close_free_key_schedule(), fragment_free(), fragment_list_buf_free(), free_context_buffers(), free_tas(), free_tls_pre_decrypt_state(), key_state_free(), link_socket_close(), management_query_cert(), management_query_pk_sig(), mbuf_free_buf(), mutate_ncp_cipher_list(), openvpn_PRF(), overlapped_io_close(), read_inline_file(), reliable_free(), send_line_crlf(), status_close(), stream_buf_close(), test_generate_reset_packet_plain(), test_incoming_push_continuation_route_accumulation(), test_incoming_push_message_1(), test_incoming_push_message_bad_format(), test_incoming_push_message_basic(), test_incoming_push_message_error1(), test_incoming_push_message_error2(), test_incoming_push_message_mix(), test_incoming_push_message_mix2(), test_incoming_push_message_not_updatable_option(), test_mbuf_add_remove(), test_parse_ack(), test_tls_crypt_teardown(), test_tls_decrypt_lite_auth(), test_tls_decrypt_lite_crypt(), test_tls_decrypt_lite_none(), test_verify_hmac_none(), test_verify_hmac_none_out_of_range_ack(), test_verify_hmac_tls_auth(), tls_crypt_v2_extract_client_key(), tls_crypt_v2_write_client_key_file(), tls_wrap_free(), tun_show_debug(), and tuntap_dhcp_mask().
Definition at line 176 of file buffer.c.
References CLEAR, buffer::data, gc, gc_arena::list, and gc_entry::next.
Referenced by buffer_read_from_file(), test_buffer_free_gc_one(), and test_buffer_free_gc_two().
| void gc_addspecial | ( | void * | addr, |
| void(*)(void *) | free_function, | ||
| struct gc_arena * | a | ||
| ) |
Register an address with a custom free function in a garbage collection arena.
When gc_free() is called on a, free_function(addr) will be invoked to release the memory. Use this for allocations that require something other than plain free(), such as freeaddrinfo().
| addr | Pointer to the memory to register. |
| free_function | Function to call to free addr. |
| a | Garbage collection arena to register with. |
Definition at line 411 of file buffer.c.
References gc_entry_special::addr, ASSERT, check_malloc_return(), gc_entry_special::free_fnc, gc_arena::list_special, and gc_entry_special::next.
Referenced by do_preresolve_host(), gc_realloc(), and init_route_list().
| void * gc_malloc | ( | size_t | size, |
| bool | clear, | ||
| struct gc_arena * | a | ||
| ) |
Allocate memory and, optionally, zero it.
The allocation is registered with a so that it is freed when gc_free() is called on the arena. Calls out_of_memory() if the allocation fails.
| size | Number of bytes to allocate. |
| clear | If true, zeroise the allocated memory before returning. |
| a | Garbage collection arena to register the allocation with. |
Definition at line 318 of file buffer.c.
References check_malloc_return(), buffer::len, gc_arena::list, and gc_entry::next.
Referenced by add_route_ipv6(), alloc_buf_gc(), append_cipher_to_ncp_list(), argv_prep_format(), argv_printf_arglist(), buf_extract_field(), dco_get_peer_stats_multi(), delete_route_ipv6(), ecdsa_sign_sig(), establish_http_proxy_passthru(), export_user_keying_material(), gc_strdup(), get_adapter_info_list(), get_device_instance_id_interface(), get_interface_info_list(), get_ipv6_addr_no_netbits(), get_panel_reg(), get_per_adapter_info(), get_user_pass_cr(), get_windows_routing_table(), options_string_extract_option(), options_warning_extract_parm1(), options_warning_safe_scan1(), options_warning_safe_scan2(), parse_auth_challenge(), parse_line(), plugin_vlog(), print_in6_addr(), print_in_addr_t(), replace_default_in_ncp_ciphers_option(), route_ipv6_ipapi(), sanitize_control_message(), setenv_str_incr(), string_alloc(), string_substitute(), utf16to8(), wide_cmd_line(), wide_string(), x509_get_subject(), and x_msg_va().
| void * gc_realloc | ( | void * | ptr, |
| size_t | size, | ||
| struct gc_arena * | a | ||
| ) |
allows to realloc a pointer previously allocated by gc_malloc or gc_realloc
| ptr | Pointer of the previously allocated memory |
| size | New size |
| a | gc_arena to use |
Definition at line 343 of file buffer.c.
References gc_entry_special::addr, ASSERT, check_malloc_return(), gc_addspecial(), gc_arena::list_special, and gc_entry_special::next.
Referenced by alloc_connection_entry(), alloc_local_entry(), alloc_remote_entry(), and test_buffer_gc_realloc().
Move all allocations from one garbage collection arena to another.
After the call src is empty and all entries previously in src are owned by dest.
| dest | Arena to move allocations into. |
| src | Arena to move allocations from (emptied on return). |
Definition at line 429 of file buffer.c.
References gc_arena::list, and gc_entry::next.
Referenced by add_option().
| const char * np | ( | const char * | str | ) |
Return a printable representation of a string that might be NULL.
| str | String to print, or NULL. |
str if non-NULL, otherwise the string "[NULL]". Definition at line 814 of file buffer.c.
References buffer::len.
| char * print_argv | ( | const char ** | p, |
| struct gc_arena * | gc, | ||
| const unsigned int | flags | ||
| ) |
Format a NULL-terminated argument vector as a single string.
| p | NULL-terminated array of string pointers to format. |
| gc | Garbage collection arena for the returned string. |
| flags | Formatting flags (e.g. PA_BRACKET). |
p. Definition at line 675 of file buffer.c.
References alloc_buf_gc(), BSTR, buf_printf(), gc, buffer::len, and PA_BRACKET.
Referenced by argv_str(), plugin_open_item(), plugin_option_list_print(), and push_options().
| void rm_trailing_chars | ( | char * | str, |
| const char * | what_to_delete | ||
| ) |
Remove all trailing characters that appear in a given set.
| str | The null-terminated string to modify in place. |
| what_to_delete | Null-terminated set of characters to strip. |
Definition at line 593 of file buffer.c.
References buffer::len.
Referenced by chomp().
| const char * skip_leading_whitespace | ( | const char * | str | ) |
Return a pointer past any leading whitespace in a string.
| str | The string to skip whitespace in. |
str is all whitespace. Definition at line 547 of file buffer.c.
References buffer::len.
Referenced by make_inline_array().
| char * string_alloc | ( | const char * | str, |
| struct gc_arena * | gc | ||
| ) |
Duplicate a string, allocating memory under garbage collection.
| str | The string to duplicate. May be NULL, in which case NULL is returned. |
| gc | Garbage collection arena for the returned string, or NULL to use plain malloc(). |
str, or NULL if str is NULL. Definition at line 616 of file buffer.c.
References check_malloc_return(), gc, gc_malloc(), and buffer::len.
Referenced by add_env_item(), argv_clone(), argv_insert_head(), argv_parse_cmd(), auth_set_client_reason(), backend_x509_get_serial(), ccs_gen_config_file(), ccs_gen_deferred_ret_file(), check_file_access(), check_inline_file(), cipher_kt_block_size(), clone_push_list(), do_close_tun(), do_init_route_ipv6_list(), extract_var_peer_info(), fork_to_self(), generate_auth_token(), get_device_instance_id_interface(), get_ipv6_addr_no_netbits(), get_p2p_ncp_cipher(), get_pa_var(), get_panel_reg(), get_proxy_authenticate(), get_tap_reg(), ifconfig_pool_acquire(), ifconfig_pool_set(), init_options_dev(), key_method_2_read(), key_state_gen_auth_control_files(), log_history_add(), make_arg_array(), make_base64_string2(), make_inline_array(), management_callback_proxy_cmd(), mutate_ncp_cipher_list(), ncp_get_best_cipher(), open_syslog(), open_tun_afunix(), open_tun_null(), options_warning_extract_parm1(), parse_auth_challenge(), parse_auth_failed_temp(), parse_hash_fingerprint_multiline(), parse_http_proxy_override(), push_option_fmt(), read_inline_file(), set_common_name(), set_win_sys_path(), ssl_put_auth_challenge(), status_open(), string_alloc_buf(), string_mod_const(), test_cipher_names(), test_list(), tls_ctx_set_tls_groups(), tls_item_in_cipher_list(), tls_lock_common_name(), tls_lock_username(), tls_poor_mans_ncp(), and tun_open_device().
Allocate a buffer containing a copy of the given string.
Wraps string_alloc(), so gc may be NULL (plain malloc() is used in that case). The buffer len reflects the string length, excluding the null terminator, even though the terminator is present in the allocated memory.
| str | The string to copy into the buffer. Must not be NULL. |
| gc | Garbage collection arena for the allocation, or NULL. |
str. Definition at line 707 of file buffer.c.
References ASSERT, buf_set_read(), gc, buffer::len, and string_alloc().
Referenced by options_warning_extract_parm1().
| int string_array_len | ( | const char ** | array | ) |
Return the number of elements in a NULL-terminated array of strings.
| array | NULL-terminated array of string pointers. |
Definition at line 661 of file buffer.c.
References buffer::len.
Referenced by make_arg_copy(), make_extended_arg_array(), no_more_than_n_args(), and openvpn_plugin_open_v3().
| bool string_check_buf | ( | const struct buffer * | buf, |
| const unsigned int | inclusive, | ||
| const unsigned int | exclusive | ||
| ) |
Check a buffer if it only consists of allowed characters.
| buf | The buffer to be checked. |
| inclusive | The character classes that are allowed. |
| exclusive | Character classes that are not allowed even if they are also in inclusive. |
Definition at line 1038 of file buffer.c.
References ASSERT, BLEN, CBSTR, char_inc_exc(), and buffer::len.
Referenced by extract_command_buffer(), test_buffer_chomp(), and test_character_string_mod_buf().
| bool string_class | ( | const char * | str, |
| const unsigned int | inclusive, | ||
| const unsigned int | exclusive | ||
| ) |
Test whether all characters in a string satisfy a character class filter.
| str | The null-terminated string to test. |
| inclusive | Classes that are permitted (characters must match at least one of these). |
| exclusive | Classes that are forbidden (characters must not match any of these, even if they also match inclusive). |
str is permitted. Definition at line 986 of file buffer.c.
References ASSERT, char_inc_exc(), and buffer::len.
Referenced by dns_addr_safe(), openvpn_inet_aton(), and push_option_ex().
| void string_clear | ( | char * | str | ) |
Securely clear a null-terminated string.
Overwrites all characters of str with zeroes.
| str | The string to clear. |
Definition at line 649 of file buffer.c.
References buffer::len, and secure_memzero().
Referenced by do_init_crypto_tls_c1(), get_user_pass_cr(), and openvpn_plugin_string_list_item_free().
| bool string_defined_equal | ( | const char * | s1, |
| const char * | s2 | ||
| ) |
Definition at line 1089 of file buffer.c.
References buffer::len.
Referenced by options_postprocess_verify_ce().
| bool string_mod | ( | char * | str, |
| const unsigned int | inclusive, | ||
| const unsigned int | exclusive, | ||
| const char | replace | ||
| ) |
Modifies a string in place by replacing certain classes of characters of it with a specified character.
Guaranteed to not increase the length of the string. If replace is 0, characters are skipped instead of replaced.
| str | The string to be modified. |
| inclusive | The character classes not to be replaced. |
| exclusive | Character classes to be replaced even if they are also in inclusive. |
| replace | The character to replace the specified character classes with. |
Definition at line 1005 of file buffer.c.
References ASSERT, char_inc_exc(), and buffer::len.
Referenced by do_setenv_x509(), get_user_pass_cr(), string_mod_const(), string_mod_remap_name(), test_character_class(), test_load_certificate_and_key_uri(), verify_user_pass(), wide_cmd_line(), and x509_setenv().
| const char * string_mod_const | ( | const char * | str, |
| const unsigned int | inclusive, | ||
| const unsigned int | exclusive, | ||
| const char | replace, | ||
| struct gc_arena * | gc | ||
| ) |
Returns a copy of a string with certain classes of characters of it replaced with a specified character.
If replace is 0, characters are skipped instead of replaced.
| str | The input string to be modified. |
| inclusive | Character classes not to be replaced. |
| exclusive | Character classes to be replaced even if they are also in inclusive. |
| replace | The character to replace the specified character classes with. |
| gc | The garbage collector arena to allocate memory from. |
Definition at line 1055 of file buffer.c.
References gc, buffer::len, string_alloc(), and string_mod().
Referenced by platform_gen_path(), safe_print(), and setenv_str_ex().
| void string_null_terminate | ( | char * | str, |
| int | len, | ||
| int | capacity | ||
| ) |
Null-terminate a fixed-length string buffer.
Ensures that str[len] is '\0', clamping len to capacity - 1 if necessary.
| str | The character buffer to null-terminate. |
| len | Current string length. |
| capacity | Total size of the character buffer in bytes. |
Definition at line 566 of file buffer.c.
References ASSERT, buffer::capacity, and buffer::len.
Referenced by get_console_input_win32().
| void string_replace_leading | ( | char * | str, |
| const char | match, | ||
| const char | replace | ||
| ) |
Replace all leading occurrences of a character in a string.
Scans from the start of str and replaces every consecutive match character with replace, stopping at the first character that does not match.
| str | The null-terminated string to modify in place. |
| match | The character to replace. |
| replace | The replacement character. |
Definition at line 1071 of file buffer.c.
References ASSERT, and buffer::len.
Referenced by verify_cert().
| char * string_substitute | ( | const char * | src, |
| char | from, | ||
| char | to, | ||
| struct gc_arena * | gc | ||
| ) |
Definition at line 1102 of file buffer.c.
References gc, gc_malloc(), and buffer::len.
Referenced by add_option().
| void x_gc_free | ( | struct gc_arena * | a | ) |
Free all plain allocations in a garbage collection arena.
Internal implementation called by gc_free(). Do not call directly.
| a | The arena whose list entries are to be freed. |
Definition at line 376 of file buffer.c.
References gc_arena::list, and gc_entry::next.
Referenced by gc_free().
| void x_gc_freespecial | ( | struct gc_arena * | a | ) |
Free all specially-allocated entries in a garbage collection arena.
Internal implementation called by gc_free(). Do not call directly. Invokes the custom free function stored in each gc_entry_special.
| a | The arena whose list_special entries are to be freed. |
Definition at line 395 of file buffer.c.
References gc_entry_special::addr, gc_entry_special::free_fnc, gc_arena::list_special, and gc_entry_special::next.
Referenced by gc_free().