OpenVPN
Data Structures | Macros | Functions
buffer.h File Reference
#include "basic.h"
#include "error.h"
Include dependency graph for buffer.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  buffer
 Wrapper structure for dynamically allocated memory. More...
 
struct  gc_entry
 Garbage collection entry for one dynamically allocated block of memory. More...
 
struct  gc_entry_special
 Garbage collection entry for a specially allocated structure that needs a custom free function to be freed like struct addrinfo. More...
 
struct  gc_arena
 Garbage collection arena used to keep track of dynamically allocated memory. More...
 
struct  buffer_entry
 
struct  buffer_list
 

Macros

#define BUF_SIZE_MAX   1000000
 
#define BPTR(buf)   (buf_bptr(buf))
 
#define BEND(buf)   (buf_bend(buf))
 
#define BLAST(buf)   (buf_blast(buf))
 
#define BLEN(buf)   (buf_len(buf))
 
#define BDEF(buf)   (buf_defined(buf))
 
#define BSTR(buf)   (buf_str(buf))
 
#define BCAP(buf)   (buf_forward_capacity(buf))
 
#define PA_BRACKET   (1<<0)
 
#define buf_init(buf, offset)   buf_init_dowork(buf, offset)
 
#define FHE_SPACE_BREAK_MASK   0xFF /* space_break parameter in lower 8 bits */
 
#define FHE_CAPS   0x100 /* output hex in caps */
 
#define CC_ANY   (1<<0)
 
#define CC_NULL   (1<<1)
 
#define CC_ALNUM   (1<<2)
 
#define CC_ALPHA   (1<<3)
 
#define CC_ASCII   (1<<4)
 
#define CC_CNTRL   (1<<5)
 
#define CC_DIGIT   (1<<6)
 
#define CC_PRINT   (1<<7)
 
#define CC_PUNCT   (1<<8)
 
#define CC_SPACE   (1<<9)
 
#define CC_XDIGIT   (1<<10)
 
#define CC_BLANK   (1<<11)
 
#define CC_NEWLINE   (1<<12)
 
#define CC_CR   (1<<13)
 
#define CC_BACKSLASH   (1<<14)
 
#define CC_UNDERBAR   (1<<15)
 
#define CC_DASH   (1<<16)
 
#define CC_DOT   (1<<17)
 
#define CC_COMMA   (1<<18)
 
#define CC_COLON   (1<<19)
 
#define CC_SLASH   (1<<20)
 
#define CC_SINGLE_QUOTE   (1<<21)
 
#define CC_DOUBLE_QUOTE   (1<<22)
 
#define CC_REVERSE_QUOTE   (1<<23)
 
#define CC_AT   (1<<24)
 
#define CC_EQUAL   (1<<25)
 
#define CC_LESS_THAN   (1<<26)
 
#define CC_GREATER_THAN   (1<<27)
 
#define CC_PIPE   (1<<28)
 
#define CC_QUESTION_MARK   (1<<29)
 
#define CC_ASTERISK   (1<<30)
 
#define CC_NAME   (CC_ALNUM|CC_UNDERBAR)
 
#define CC_CRLF   (CC_CR|CC_NEWLINE)
 
#define verify_align_4(ptr)
 
#define ALLOC_OBJ(dptr, type)
 
#define ALLOC_OBJ_CLEAR(dptr, type)
 
#define ALLOC_ARRAY(dptr, type, n)
 
#define ALLOC_ARRAY_GC(dptr, type, n, gc)
 
#define ALLOC_ARRAY_CLEAR(dptr, type, n)
 
#define ALLOC_ARRAY_CLEAR_GC(dptr, type, n, gc)
 
#define ALLOC_VAR_ARRAY_CLEAR_GC(dptr, type, atype, n, gc)
 
#define ALLOC_OBJ_GC(dptr, type, gc)
 
#define ALLOC_OBJ_CLEAR_GC(dptr, type, gc)
 

Functions

void buf_clear (struct buffer *buf)
 
void free_buf (struct buffer *buf)
 
bool buf_assign (struct buffer *dest, const struct buffer *src)
 
void string_clear (char *str)
 
int string_array_len (const char **array)
 
size_t array_mult_safe (const size_t m1, const size_t m2, const size_t extra)
 
char * print_argv (const char **p, struct gc_arena *gc, const unsigned int flags)
 
void buf_size_error (const size_t size)
 
struct buffer alloc_buf (size_t size)
 
struct buffer alloc_buf_gc (size_t size, struct gc_arena *gc)
 
struct buffer clone_buf (const struct buffer *buf)
 
void * gc_malloc (size_t size, bool clear, struct gc_arena *a)
 
char * string_alloc (const char *str, struct gc_arena *gc)
 
struct buffer string_alloc_buf (const char *str, struct gc_arena *gc)
 
void gc_addspecial (void *addr, void(*free_function)(void *), struct gc_arena *a)
 
static void gc_freeaddrinfo_callback (void *addr)
 
static struct buffer clear_buf (void)
 Return an empty struct buffer. More...
 
static bool buf_defined (const struct buffer *buf)
 
static bool buf_valid (const struct buffer *buf)
 
static uint8_tbuf_bptr (const struct buffer *buf)
 
static int buf_len (const struct buffer *buf)
 
static uint8_tbuf_bend (const struct buffer *buf)
 
static uint8_tbuf_blast (const struct buffer *buf)
 
static bool buf_size_valid (const size_t size)
 
static bool buf_size_valid_signed (const int size)
 
static char * buf_str (const struct buffer *buf)
 
static void buf_reset (struct buffer *buf)
 
static void buf_reset_len (struct buffer *buf)
 
static bool buf_init_dowork (struct buffer *buf, int offset)
 
static void buf_set_write (struct buffer *buf, uint8_t *data, int size)
 
static void buf_set_read (struct buffer *buf, const uint8_t *data, int size)
 
static void strncpynt (char *dest, const char *src, size_t maxlen)
 
static bool has_digit (const unsigned char *src)
 
static void secure_memzero (void *data, size_t len)
 Securely zeroise memory. More...
 
bool buf_printf (struct buffer *buf, const char *format,...)
 
bool buf_puts (struct buffer *buf, const char *str)
 
bool openvpn_snprintf (char *str, size_t size, const char *format,...)
 
bool openvpn_swprintf (wchar_t *const str, const size_t size, const wchar_t *const format,...)
 
void buf_null_terminate (struct buffer *buf)
 
void buf_chomp (struct buffer *buf)
 
void buf_rmtail (struct buffer *buf, uint8_t remove)
 
void chomp (char *str)
 
void rm_trailing_chars (char *str, const char *what_to_delete)
 
const char * skip_leading_whitespace (const char *str)
 
void string_null_terminate (char *str, int len, int capacity)
 
bool buffer_write_file (const char *filename, const struct buffer *buf)
 Write buffer contents to file. More...
 
void buf_catrunc (struct buffer *buf, const char *str)
 
void convert_to_one_line (struct buffer *buf)
 
bool buf_parse (struct buffer *buf, const int delim, char *line, const int size)
 
char * format_hex_ex (const uint8_t *data, int size, int maxoutput, unsigned int space_break_flags, const char *separator, struct gc_arena *gc)
 
static char * format_hex (const uint8_t *data, int size, int maxoutput, struct gc_arena *gc)
 
struct buffer buf_sub (struct buffer *buf, int size, bool prepend)
 
static bool buf_safe (const struct buffer *buf, int len)
 
static bool buf_safe_bidir (const struct buffer *buf, int len)
 
static int buf_forward_capacity (const struct buffer *buf)
 
static int buf_forward_capacity_total (const struct buffer *buf)
 
static int buf_reverse_capacity (const struct buffer *buf)
 
static bool buf_inc_len (struct buffer *buf, int inc)
 
static uint8_tbuf_prepend (struct buffer *buf, int size)
 
static bool buf_advance (struct buffer *buf, int size)
 
static uint8_tbuf_write_alloc (struct buffer *buf, int size)
 
static uint8_tbuf_write_alloc_prepend (struct buffer *buf, int size, bool prepend)
 
static uint8_tbuf_read_alloc (struct buffer *buf, int size)
 
static bool buf_write (struct buffer *dest, const void *src, int size)
 
static bool buf_write_prepend (struct buffer *dest, const void *src, int size)
 
static bool buf_write_u8 (struct buffer *dest, int data)
 
static bool buf_write_u16 (struct buffer *dest, int data)
 
static bool buf_write_u32 (struct buffer *dest, int data)
 
static bool buf_copy (struct buffer *dest, const struct buffer *src)
 
static bool buf_copy_n (struct buffer *dest, struct buffer *src, int n)
 
static bool buf_copy_range (struct buffer *dest, int dest_index, const struct buffer *src, int src_index, int src_len)
 
static bool buf_copy_excess (struct buffer *dest, struct buffer *src, int len)
 
static bool buf_read (struct buffer *src, void *dest, int size)
 
static int buf_read_u8 (struct buffer *buf)
 
static int buf_read_u16 (struct buffer *buf)
 
static uint32_t buf_read_u32 (struct buffer *buf, bool *good)
 
static bool buf_equal (const struct buffer *a, const struct buffer *b)
 Return true if buffer contents are equal. More...
 
static bool buf_string_match (const struct buffer *src, const void *match, int size)
 Compare src buffer contents with match. More...
 
static bool buf_string_match_head (const struct buffer *src, const void *match, int size)
 Compare first size bytes of src buffer contents with match. More...
 
bool buf_string_match_head_str (const struct buffer *src, const char *match)
 
bool buf_string_compare_advance (struct buffer *src, const char *match)
 
int buf_substring_len (const struct buffer *buf, int delim)
 
const char * np (const char *str)
 
bool char_class (const unsigned char c, const unsigned int flags)
 
bool string_class (const char *str, const unsigned int inclusive, const unsigned int exclusive)
 
bool string_mod (char *str, const unsigned int inclusive, const unsigned int exclusive, const char replace)
 
const char * string_mod_const (const char *str, const unsigned int inclusive, const unsigned int exclusive, const char replace, struct gc_arena *gc)
 
void string_replace_leading (char *str, const char match, const char replace)
 
static bool strprefix (const char *str, const char *prefix)
 Return true iff str starts with prefix. More...
 
void gc_transfer (struct gc_arena *dest, struct gc_arena *src)
 
void x_gc_free (struct gc_arena *a)
 
void x_gc_freespecial (struct gc_arena *a)
 
static bool gc_defined (struct gc_arena *a)
 
static void gc_init (struct gc_arena *a)
 
static void gc_detach (struct gc_arena *a)
 
static struct gc_arena gc_new (void)
 
static void gc_free (struct gc_arena *a)
 
static void gc_reset (struct gc_arena *a)
 
static void check_malloc_return (const void *p)
 
struct buffer_listbuffer_list_new (const int max_size)
 Allocate an empty buffer list of capacity max_size. More...
 
void buffer_list_free (struct buffer_list *ol)
 Frees a buffer list and all the buffers in it. More...
 
bool buffer_list_defined (const struct buffer_list *ol)
 Checks if the list is valid and non-empty. More...
 
void buffer_list_reset (struct buffer_list *ol)
 Empty the list ol and frees all the contained buffers. More...
 
void buffer_list_push (struct buffer_list *ol, const char *str)
 Allocates and appends a new buffer containing str as data to ol. More...
 
struct buffer_entrybuffer_list_push_data (struct buffer_list *ol, const void *data, size_t size)
 Allocates and appends a new buffer containing data of length size. More...
 
struct bufferbuffer_list_peek (struct buffer_list *ol)
 Retrieve the head buffer. More...
 
void buffer_list_advance (struct buffer_list *ol, int n)
 
void buffer_list_pop (struct buffer_list *ol)
 
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 . More...
 
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 . More...
 
struct buffer_listbuffer_list_file (const char *fn, int max_line_len)
 
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 More...
 

Macro Definition Documentation

◆ ALLOC_ARRAY

#define ALLOC_ARRAY (   dptr,
  type,
 
)
Value:
{ \
check_malloc_return((dptr) = (type *) malloc(array_mult_safe(sizeof(type), (n), 0))); \
}
size_t array_mult_safe(const size_t m1, const size_t m2, const size_t extra)
Definition: buffer.c:43
#define malloc
Definition: cmocka.c:1795

Definition at line 1055 of file buffer.h.

Referenced by hash_init(), mbuf_init(), multi_tcp_init(), schedule_remove_entry(), and show_available_curves().

◆ ALLOC_ARRAY_CLEAR

#define ALLOC_ARRAY_CLEAR (   dptr,
  type,
 
)
Value:
{ \
ALLOC_ARRAY(dptr, type, n); \
memset((dptr), 0, (array_mult_safe(sizeof(type), (n), 0))); \
}
size_t array_mult_safe(const size_t m1, const size_t m2, const size_t extra)
Definition: buffer.c:43

Definition at line 1065 of file buffer.h.

Referenced by argv_extend(), ifconfig_pool_init(), log_history_obj_init(), and we_init().

◆ ALLOC_ARRAY_CLEAR_GC

#define ALLOC_ARRAY_CLEAR_GC (   dptr,
  type,
  n,
  gc 
)
Value:
{ \
(dptr) = (type *) gc_malloc(array_mult_safe(sizeof(type), (n), 0), true, (gc)); \
}
size_t array_mult_safe(const size_t m1, const size_t m2, const size_t extra)
Definition: buffer.c:43
void * gc_malloc(size_t size, bool clear, struct gc_arena *a)
Definition: buffer.c:408

Definition at line 1071 of file buffer.h.

Referenced by ifconfig_pool_read(), key_method_2_read(), make_arg_array(), make_arg_copy(), make_env_array(), make_inline_array(), and verify_user_pass().

◆ ALLOC_ARRAY_GC

#define ALLOC_ARRAY_GC (   dptr,
  type,
  n,
  gc 
)
Value:
{ \
(dptr) = (type *) gc_malloc(array_mult_safe(sizeof(type), (n), 0), false, (gc)); \
}
size_t array_mult_safe(const size_t m1, const size_t m2, const size_t extra)
Definition: buffer.c:43
void * gc_malloc(size_t size, bool clear, struct gc_arena *a)
Definition: buffer.c:408

Definition at line 1060 of file buffer.h.

Referenced by add_option().

◆ ALLOC_OBJ

#define ALLOC_OBJ (   dptr,
  type 
)
Value:
{ \
check_malloc_return((dptr) = (type *) malloc(sizeof(type))); \
}
#define malloc
Definition: cmocka.c:1795

Definition at line 1044 of file buffer.h.

Referenced by cert_hash_copy(), cert_hash_remember(), frequency_limit_init(), hash_add_fast(), init_tun(), log_history_init(), mbuf_alloc_buf(), multi_learn_addr(), multi_reap_new(), and open_null().

◆ ALLOC_OBJ_CLEAR

#define ALLOC_OBJ_CLEAR (   dptr,
  type 
)

◆ ALLOC_OBJ_CLEAR_GC

#define ALLOC_OBJ_CLEAR_GC (   dptr,
  type,
  gc 
)

◆ ALLOC_OBJ_GC

#define ALLOC_OBJ_GC (   dptr,
  type,
  gc 
)

◆ ALLOC_VAR_ARRAY_CLEAR_GC

#define ALLOC_VAR_ARRAY_CLEAR_GC (   dptr,
  type,
  atype,
  n,
  gc 
)
Value:
{ \
(dptr) = (type *) gc_malloc(array_mult_safe(sizeof(atype), (n), sizeof(type)), true, (gc)); \
}
size_t array_mult_safe(const size_t m1, const size_t m2, const size_t extra)
Definition: buffer.c:43
void * gc_malloc(size_t size, bool clear, struct gc_arena *a)
Definition: buffer.c:408

Definition at line 1076 of file buffer.h.

◆ BCAP

#define BCAP (   buf)    (buf_forward_capacity(buf))

◆ BDEF

#define BDEF (   buf)    (buf_defined(buf))

Definition at line 128 of file buffer.h.

Referenced by reliable_ack_write().

◆ BEND

#define BEND (   buf)    (buf_bend(buf))

◆ BLAST

#define BLAST (   buf)    (buf_blast(buf))

Definition at line 126 of file buffer.h.

Referenced by buf_chomp(), buf_null_terminate(), and buf_rmtail().

◆ BLEN

#define BLEN (   buf)    (buf_len(buf))

Definition at line 127 of file buffer.h.

Referenced by bio_read(), bio_write_post(), buf_assign(), buf_copy(), buf_equal(), buf_read_u8(), buffer_list_advance(), buffer_list_aggregate_separator(), buffer_write_file(), cert_hash_remember(), check_send_occ_msg_dowork(), client_nat_transform(), clone_buf(), convert_to_one_line(), crypto_pem_decode(), crypto_pem_encode(), crypto_pem_encode_decode_loopback(), dhcp_extract_router_msg(), drop_if_recursive_routing(), establish_http_proxy_passthru(), get_tun_ip_ver(), get_user_pass_cr(), ifconfig_pool_read(), is_ipv6(), is_ipv_X(), key_state_write_ciphertext(), key_state_write_plaintext(), link_socket_read_tcp(), link_socket_write_tcp(), link_socket_write_win32(), man_write(), management_query_multiline_flatten(), management_query_multiline_flatten_newline(), mroute_extract_addr_ether(), mroute_extract_addr_ip(), mroute_is_mcast_ipv6(), mss_fixup_dowork(), mss_fixup_ipv4(), mss_fixup_ipv6(), multi_bcast(), multi_process_incoming_link(), multi_process_incoming_tun(), multi_tcp_process_outgoing_link(), multi_unicast(), open_tun(), openvpn_decrypt_aead(), openvpn_decrypt_v1(), openvpn_encrypt_aead(), openvpn_encrypt_v1(), openvpn_PRF(), process_incoming_link_part1(), process_incoming_link_part2(), process_incoming_tun(), process_outgoing_link(), process_outgoing_tun(), protocol_dump(), read_incoming_tun(), receive_auth_failed(), send_push_options(), send_push_reply(), server_pushed_signal(), socket_recv_queue(), socket_send_queue(), socks_process_incoming_udp(), stream_buf_added(), test_buffer_list_aggregate_separator_emptybuffers(), test_crypto(), tls_crypt_fail_invalid_key(), tls_crypt_fail_msg_too_long(), tls_crypt_fail_replay(), tls_crypt_ignore_replay(), tls_crypt_loopback(), tls_crypt_loopback_max_len(), tls_crypt_loopback_zero_len(), tls_crypt_unwrap(), tls_crypt_v2_extract_client_key(), tls_crypt_v2_unwrap_client_key(), tls_crypt_v2_wrap_client_key(), tls_crypt_v2_wrap_unwrap_dst_too_small(), tls_crypt_v2_wrap_unwrap_wrong_key(), tls_crypt_wrap(), tls_rec_payload(), tls_test_payload_len(), tun_read_queue(), tun_write_queue(), tun_write_win32(), verify_cert(), verify_cert_set_env(), and x509_setenv_track().

◆ BPTR

#define BPTR (   buf)    (buf_bptr(buf))

Definition at line 124 of file buffer.h.

Referenced by bio_read(), bio_write_post(), buf_assign(), buf_copy(), buf_equal(), buf_prepend(), buf_read_alloc(), buf_read_u8(), buf_string_match(), buf_string_match_head(), buf_string_match_head_str(), buf_write_alloc(), buffer_read_from_file(), buffer_write_file(), cert_hash_remember(), client_nat_transform(), clone_buf(), convert_to_one_line(), crypto_pem_decode(), crypto_pem_encode(), crypto_pem_encode_decode_loopback(), dhcp_extract_router_msg(), drop_if_recursive_routing(), establish_http_proxy_passthru(), get_tun_ip_ver(), is_ipv6(), is_ipv_X(), key_method_1_read(), key_state_write_ciphertext(), key_state_write_plaintext(), link_socket_read_tcp(), link_socket_write(), link_socket_write_tcp(), link_socket_write_win32(), man_write(), mroute_extract_addr_ether(), mroute_extract_addr_ip(), mroute_is_mcast_ipv6(), mss_fixup_dowork(), mss_fixup_ipv4(), mss_fixup_ipv6(), multi_get_create_instance_udp(), netsh_get_id(), open_tun(), openvpn_decrypt_aead(), openvpn_decrypt_v1(), openvpn_encrypt_aead(), openvpn_encrypt_v1(), openvpn_PRF(), options_string_version(), process_incoming_link_part1(), process_incoming_link_part2(), process_incoming_tun(), process_outgoing_tun(), process_received_occ_msg(), protocol_dump(), read_control_auth(), read_incoming_tun(), socket_recv_queue(), socket_send_queue(), status_read(), string_replace_leading(), swap_hmac(), test_crypto(), tls_crypt_loopback(), tls_crypt_loopback_max_len(), tls_crypt_loopback_zero_len(), tls_crypt_unwrap(), tls_crypt_v2_unwrap_client_key(), tls_crypt_v2_wrap_client_key(), tls_crypt_v2_write_client_key_file(), tls_crypt_wrap(), tls_pre_decrypt(), tls_pre_decrypt_lite(), tun_read_queue(), tun_write_queue(), verify_cert(), verify_cert_set_env(), x509_get_sha1_fingerprint(), x509_get_sha256_fingerprint(), and x509_setenv_track().

◆ BSTR

#define BSTR (   buf)    (buf_str(buf))

Definition at line 129 of file buffer.h.

Referenced by add_option(), ce_management_query_proxy(), ce_management_query_remote(), check_file_access_chroot(), check_incoming_control_channel_dowork(), check_inline_file(), command_line_get(), construct_name_value(), foreign_option(), fork_dhcp_action(), fork_register_dns_action(), format_common_name(), format_ip_addr_string(), format_route_entry(), get_auth_challenge(), get_device_guid(), get_unspecified_device_guid(), get_user_pass_cr(), hostname_randomize(), ifconfig_options_string(), ifconfig_pool_read(), incoming_push_message(), ipset2ascii_all(), link_socket_connection_initiated(), log_entry_print(), management_hold(), management_query_multiline(), management_query_user_pass(), mroute_addr_print_ex(), mroute_helper_regenerate(), msg_flags_string(), multi_client_connect_post_plugin(), multi_instance_string(), ntlm_phase_1(), options_string(), options_string_version(), packet_id_net_print(), packet_id_persist_print(), platform_gen_path(), plugin_mask_string(), print_argv(), print_default_gateway(), print_in6_addr(), print_in_addr_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(), print_str_int(), proto2ascii_all(), protocol_dump(), push_peer_info(), read_inline_file(), receive_auth_failed(), reliable_ack_print(), reliable_print_ids(), route_string(), send_auth_failed(), send_line_crlf(), send_push_options(), send_push_reply(), server_pushed_signal(), setenv_format_indexed_name(), setenv_route(), setenv_route_addr(), setenv_route_ipv6(), setenv_str_safe(), socket_stat(), strerror_win32(), tap_win_getinfo(), time_string(), translate_mtu_discover_type_name(), tun_show_debug(), tun_stat(), tv_string(), username_password_as_base64(), wide_cmd_line(), and window_title_generate().

◆ buf_init

#define buf_init (   buf,
  offset 
)    buf_init_dowork(buf, offset)

◆ BUF_SIZE_MAX

#define BUF_SIZE_MAX   1000000

Definition at line 30 of file buffer.h.

Referenced by buf_size_valid(), and buf_size_valid_signed().

◆ CC_ALNUM

#define CC_ALNUM   (1<<2)

Definition at line 909 of file buffer.h.

Referenced by char_class(), and dns_addr_safe().

◆ CC_ALPHA

#define CC_ALPHA   (1<<3)

Definition at line 910 of file buffer.h.

Referenced by char_class().

◆ CC_ANY

#define CC_ANY   (1<<0)

Definition at line 906 of file buffer.h.

Referenced by char_class(), do_setenv_x509(), push_option_ex(), and wide_cmd_line().

◆ CC_ASCII

#define CC_ASCII   (1<<4)

Definition at line 911 of file buffer.h.

Referenced by char_class().

◆ CC_ASTERISK

#define CC_ASTERISK   (1<<30)

Definition at line 939 of file buffer.h.

Referenced by char_class(), and platform_gen_path().

◆ CC_AT

#define CC_AT   (1<<24)

Definition at line 933 of file buffer.h.

Referenced by char_class().

◆ CC_BACKSLASH

#define CC_BACKSLASH   (1<<14)

Definition at line 923 of file buffer.h.

Referenced by char_class(), and platform_gen_path().

◆ CC_BLANK

#define CC_BLANK   (1<<11)

Definition at line 919 of file buffer.h.

Referenced by char_class().

◆ CC_CNTRL

#define CC_CNTRL   (1<<5)

Definition at line 912 of file buffer.h.

Referenced by char_class().

◆ CC_COLON

#define CC_COLON   (1<<19)

Definition at line 928 of file buffer.h.

Referenced by char_class(), and platform_gen_path().

◆ CC_COMMA

#define CC_COMMA   (1<<18)

Definition at line 927 of file buffer.h.

Referenced by char_class(), and push_option_ex().

◆ CC_CR

#define CC_CR   (1<<13)

Definition at line 921 of file buffer.h.

Referenced by char_class().

◆ CC_CRLF

#define CC_CRLF   (CC_CR|CC_NEWLINE)

◆ CC_DASH

#define CC_DASH   (1<<16)

Definition at line 925 of file buffer.h.

Referenced by char_class(), and dns_addr_safe().

◆ CC_DIGIT

#define CC_DIGIT   (1<<6)

Definition at line 913 of file buffer.h.

Referenced by char_class(), and openvpn_inet_aton().

◆ CC_DOT

#define CC_DOT   (1<<17)

Definition at line 926 of file buffer.h.

Referenced by char_class(), dns_addr_safe(), and openvpn_inet_aton().

◆ CC_DOUBLE_QUOTE

#define CC_DOUBLE_QUOTE   (1<<22)

Definition at line 931 of file buffer.h.

Referenced by char_class(), platform_gen_path(), and wide_cmd_line().

◆ CC_EQUAL

#define CC_EQUAL   (1<<25)

Definition at line 934 of file buffer.h.

Referenced by char_class().

◆ CC_GREATER_THAN

#define CC_GREATER_THAN   (1<<27)

Definition at line 936 of file buffer.h.

Referenced by char_class(), and platform_gen_path().

◆ CC_LESS_THAN

#define CC_LESS_THAN   (1<<26)

Definition at line 935 of file buffer.h.

Referenced by char_class(), and platform_gen_path().

◆ CC_NAME

#define CC_NAME   (CC_ALNUM|CC_UNDERBAR)

Definition at line 942 of file buffer.h.

Referenced by setenv_str().

◆ CC_NEWLINE

#define CC_NEWLINE   (1<<12)

Definition at line 920 of file buffer.h.

Referenced by char_class(), and command_line_add().

◆ CC_NULL

#define CC_NULL   (1<<1)

Definition at line 907 of file buffer.h.

Referenced by buf_chomp(), and char_class().

◆ CC_PIPE

#define CC_PIPE   (1<<28)

Definition at line 937 of file buffer.h.

Referenced by char_class(), and platform_gen_path().

◆ CC_PRINT

#define CC_PRINT   (1<<7)

◆ CC_PUNCT

#define CC_PUNCT   (1<<8)

Definition at line 915 of file buffer.h.

Referenced by char_class().

◆ CC_QUESTION_MARK

#define CC_QUESTION_MARK   (1<<29)

Definition at line 938 of file buffer.h.

Referenced by char_class(), and platform_gen_path().

◆ CC_REVERSE_QUOTE

#define CC_REVERSE_QUOTE   (1<<23)

Definition at line 932 of file buffer.h.

Referenced by char_class().

◆ CC_SINGLE_QUOTE

#define CC_SINGLE_QUOTE   (1<<21)

Definition at line 930 of file buffer.h.

Referenced by char_class().

◆ CC_SLASH

#define CC_SLASH   (1<<20)

Definition at line 929 of file buffer.h.

Referenced by char_class(), and platform_gen_path().

◆ CC_SPACE

#define CC_SPACE   (1<<9)

Definition at line 916 of file buffer.h.

Referenced by char_class(), and wide_cmd_line().

◆ CC_UNDERBAR

#define CC_UNDERBAR   (1<<15)

Definition at line 924 of file buffer.h.

Referenced by char_class().

◆ CC_XDIGIT

#define CC_XDIGIT   (1<<10)

Definition at line 917 of file buffer.h.

Referenced by char_class().

◆ FHE_CAPS

#define FHE_CAPS   0x100 /* output hex in caps */

Definition at line 518 of file buffer.h.

Referenced by format_hex_ex(), and x509_setenv_track().

◆ FHE_SPACE_BREAK_MASK

#define FHE_SPACE_BREAK_MASK   0xFF /* space_break parameter in lower 8 bits */

Definition at line 517 of file buffer.h.

Referenced by format_hex_ex().

◆ PA_BRACKET

#define PA_BRACKET   (1<<0)

◆ verify_align_4

#define verify_align_4 (   ptr)

Function Documentation

◆ alloc_buf()

struct buffer alloc_buf ( size_t  size)

◆ alloc_buf_gc()

struct buffer alloc_buf_gc ( size_t  size,
struct gc_arena gc 
)

Definition at line 90 of file buffer.c.

References buf_size_error(), buf_size_valid(), buffer::capacity, buffer::data, gc_malloc(), buffer::len, and buffer::offset.

Referenced by add_option(), add_route_ipv6(), buffer_read_from_file(), ce_management_query_proxy(), ce_management_query_remote(), check_file_access_chroot(), check_incoming_control_channel_dowork(), construct_name_value(), crypto_pem_encode(), delete_route_ipv6(), foreign_option(), 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(), ifconfig_pool_read(), ipset2ascii_all(), link_socket_connection_initiated(), log_entry_print(), management_hold(), management_query_multiline(), management_query_user_pass(), mroute_addr_print_ex(), mroute_helper_regenerate(), msg_flags_string(), multi_instance_string(), netsh_get_id(), ntlm_phase_1(), options_string_version(), options_warning_safe_ml(), packet_id_net_print(), packet_id_persist_print(), platform_gen_path(), plugin_mask_string(), print_argv(), print_default_gateway(), print_in6_addr(), print_in_addr_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(), print_str_int(), proto2ascii_all(), protocol_dump(), push_peer_info(), read_control_auth(), reliable_ack_print(), reliable_print_ids(), route_quota_exceeded(), route_string(), send_auth_failed(), send_push_reply(), setenv_format_indexed_name(), setenv_route(), setenv_route_addr(), setenv_route_ipv6(), socket_stat(), strerror_win32(), system_error_message(), tap_win_getinfo(), test_buffer_free_gc_one(), test_buffer_free_gc_two(), test_crypto(), test_tls_crypt_v2_setup(), 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(), translate_mtu_discover_type_name(), tun_stat(), tv_string(), username_password_as_base64(), wide_cmd_line(), win32_version_string(), window_title_generate(), write_key_file(), x509_get_sha1_fingerprint(), and x509_get_sha256_fingerprint().

◆ array_mult_safe()

size_t array_mult_safe ( const size_t  m1,
const size_t  m2,
const size_t  extra 
)

Definition at line 43 of file buffer.c.

References M_FATAL, msg, and unlikely.

◆ buf_advance()

static bool buf_advance ( struct buffer buf,
int  size 
)
inlinestatic

◆ buf_assign()

bool buf_assign ( struct buffer dest,
const struct buffer src 
)

Definition at line 175 of file buffer.c.

References BLEN, BPTR, buf_init, buf_write(), and buffer::offset.

Referenced by buffer_turnover().

◆ buf_bend()

static uint8_t* buf_bend ( const struct buffer buf)
inlinestatic

Definition at line 253 of file buffer.h.

References buf_bptr(), and buf_len().

◆ buf_blast()

static uint8_t* buf_blast ( const struct buffer buf)
inlinestatic

Definition at line 259 of file buffer.h.

References buf_bptr(), and buf_len().

◆ buf_bptr()

static uint8_t* buf_bptr ( const struct buffer buf)
inlinestatic

◆ buf_catrunc()

void buf_catrunc ( struct buffer buf,
const char *  str 
)

◆ buf_chomp()

void buf_chomp ( struct buffer buf)

Definition at line 593 of file buffer.c.

References BLAST, buf_inc_len(), buf_null_terminate(), CC_CRLF, CC_NULL, and char_class().

Referenced by command_line_get(), and secure_memzero().

◆ buf_clear()

void buf_clear ( struct buffer buf)

◆ buf_copy()

static bool buf_copy ( struct buffer dest,
const struct buffer src 
)
inlinestatic

◆ buf_copy_excess()

static bool buf_copy_excess ( struct buffer dest,
struct buffer src,
int  len 
)
inlinestatic

Definition at line 774 of file buffer.h.

References buf_advance(), buf_copy(), and buffer::len.

Referenced by command_line_get(), and stream_buf_added().

◆ buf_copy_n()

static bool buf_copy_n ( struct buffer dest,
struct buffer src,
int  n 
)
inlinestatic

Definition at line 739 of file buffer.h.

References buf_read_alloc(), and buf_write().

Referenced by fragment_ready_to_send().

◆ buf_copy_range()

static bool buf_copy_range ( struct buffer dest,
int  dest_index,
const struct buffer src,
int  src_index,
int  src_len 
)
inlinestatic

Definition at line 750 of file buffer.h.

References buffer::capacity, buffer::data, buffer::len, and buffer::offset.

Referenced by fragment_incoming().

◆ buf_defined()

static bool buf_defined ( const struct buffer buf)
inlinestatic

◆ buf_equal()

static bool buf_equal ( const struct buffer a,
const struct buffer b 
)
inlinestatic

Return true if buffer contents are equal.

Definition at line 858 of file buffer.h.

References BLEN, and BPTR.

Referenced by tls_crypt_v2_wrap_unwrap_max_metadata().

◆ buf_forward_capacity()

static int buf_forward_capacity ( const struct buffer buf)
inlinestatic

◆ buf_forward_capacity_total()

static int buf_forward_capacity_total ( const struct buffer buf)
inlinestatic

Definition at line 579 of file buffer.h.

References buf_valid(), buffer::capacity, and buffer::offset.

Referenced by buf_catrunc(), link_socket_read_tcp(), and read_control_auth().

◆ buf_inc_len()

static bool buf_inc_len ( struct buffer buf,
int  inc 
)
inlinestatic

◆ buf_init_dowork()

static bool buf_init_dowork ( struct buffer buf,
int  offset 
)
inlinestatic

Definition at line 306 of file buffer.h.

References buffer::capacity, buffer::data, buffer::len, and buffer::offset.

Referenced by clone_buf().

◆ buf_len()

static int buf_len ( const struct buffer buf)
static

Definition at line 240 of file buffer.h.

References buf_valid(), and buffer::len.

Referenced by buf_bend(), buf_blast(), tls_crypt_unwrap(), and tls_crypt_v2_unwrap_client_key().

◆ buf_null_terminate()

void buf_null_terminate ( struct buffer buf)

◆ buf_parse()

bool buf_parse ( struct buffer buf,
const int  delim,
char *  line,
const int  size 
)

◆ buf_prepend()

static uint8_t* buf_prepend ( struct buffer buf,
int  size 
)
inlinestatic

◆ buf_printf()

bool buf_printf ( struct buffer buf,
const char *  format,
  ... 
)

Definition at line 245 of file buffer.c.

References BEND, buf_defined(), buf_forward_capacity(), buffer::capacity, buffer::data, buffer::len, and vsnprintf.

Referenced by add_option(), add_route_ipv6(), ce_management_query_proxy(), ce_management_query_remote(), check_file_access_chroot(), check_inline_file(), construct_name_value(), delete_route_ipv6(), foreign_option(), 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_hold(), management_query_multiline(), management_query_user_pass(), mroute_addr_print_ex(), mroute_helper_regenerate(), msg_flags_string(), multi_instance_string(), ntlm_phase_1(), options_string(), options_warning_safe_ml(), packet_id_net_print(), packet_id_persist_print(), platform_gen_path(), plugin_mask_string(), print_argv(), print_default_gateway(), print_in6_addr(), print_in_addr_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(), print_str_int(), proto2ascii_all(), protocol_dump(), push_peer_info(), read_inline_file(), reliable_ack_print(), reliable_print_ids(), route_string(), secure_memzero(), send_auth_failed(), send_push_options(), send_push_reply(), setenv_format_indexed_name(), setenv_route(), setenv_route_addr(), setenv_route_ipv6(), setenv_str_safe(), socket_stat(), strerror_win32(), system_error_message(), time_string(), translate_mtu_discover_type_name(), tun_stat(), tv_string(), username_password_as_base64(), wide_cmd_line(), win32_version_string(), window_title_generate(), and write_key_file().

◆ buf_puts()

bool buf_puts ( struct buffer buf,
const char *  str 
)

◆ buf_read()

static bool buf_read ( struct buffer src,
void *  dest,
int  size 
)
inlinestatic

◆ buf_read_alloc()

static uint8_t* buf_read_alloc ( struct buffer buf,
int  size 
)
inlinestatic

Definition at line 674 of file buffer.h.

References BPTR, buffer::len, and buffer::offset.

Referenced by buf_copy_n(), buf_read(), key_des_check(), and key_des_fixup().

◆ buf_read_u16()

static int buf_read_u16 ( struct buffer buf)
inlinestatic

◆ buf_read_u32()

static uint32_t buf_read_u32 ( struct buffer buf,
bool good 
)
inlinestatic

Definition at line 835 of file buffer.h.

References buf_read().

◆ buf_read_u8()

static int buf_read_u8 ( struct buffer buf)
inlinestatic

◆ buf_reset()

static void buf_reset ( struct buffer buf)
inlinestatic

◆ buf_reset_len()

static void buf_reset_len ( struct buffer buf)
inlinestatic

Definition at line 299 of file buffer.h.

References buffer::len, and buffer::offset.

Referenced by multi_process_incoming_tun(), send_push_options(), and send_push_reply().

◆ buf_reverse_capacity()

static int buf_reverse_capacity ( const struct buffer buf)
inlinestatic

Definition at line 597 of file buffer.h.

References buf_valid(), and buffer::offset.

◆ buf_rmtail()

void buf_rmtail ( struct buffer buf,
uint8_t  remove 
)

Definition at line 557 of file buffer.c.

References BLAST, and buffer::len.

Referenced by secure_memzero(), time_string(), and translate_mtu_discover_type_name().

◆ buf_safe()

static bool buf_safe ( const struct buffer buf,
int  len 
)
inlinestatic

◆ buf_safe_bidir()

static bool buf_safe_bidir ( const struct buffer buf,
int  len 
)
inlinestatic

Definition at line 547 of file buffer.h.

References buf_size_valid_signed(), buf_valid(), buffer::capacity, buffer::len, and buffer::offset.

Referenced by buf_inc_len().

◆ buf_set_read()

static void buf_set_read ( struct buffer buf,
const uint8_t data,
int  size 
)
inlinestatic

◆ buf_set_write()

static void buf_set_write ( struct buffer buf,
uint8_t data,
int  size 
)
inlinestatic

◆ buf_size_error()

void buf_size_error ( const size_t  size)

Definition at line 55 of file buffer.c.

References M_FATAL, and msg.

Referenced by alloc_buf(), alloc_buf_gc(), buf_set_read(), and buf_set_write().

◆ buf_size_valid()

static bool buf_size_valid ( const size_t  size)
inlinestatic

Definition at line 272 of file buffer.h.

References BUF_SIZE_MAX, and likely.

Referenced by alloc_buf(), alloc_buf_gc(), buf_safe(), buf_set_read(), and buf_set_write().

◆ buf_size_valid_signed()

static bool buf_size_valid_signed ( const int  size)
inlinestatic

Definition at line 278 of file buffer.h.

References BUF_SIZE_MAX, and likely.

Referenced by buf_safe_bidir().

◆ buf_str()

static char* buf_str ( const struct buffer buf)
inlinestatic

Definition at line 284 of file buffer.h.

References buf_bptr().

◆ buf_string_compare_advance()

bool buf_string_compare_advance ( struct buffer src,
const char *  match 
)

◆ buf_string_match()

static bool buf_string_match ( const struct buffer src,
const void *  match,
int  size 
)
inlinestatic

Compare src buffer contents with match.

NOT constant time. Do not use when comparing HMACs.

Definition at line 868 of file buffer.h.

References BPTR, and buffer::len.

Referenced by is_ping_msg().

◆ buf_string_match_head()

static bool buf_string_match_head ( const struct buffer src,
const void *  match,
int  size 
)
inlinestatic

Compare first size bytes of src buffer contents with match.

NOT constant time. Do not use when comparing HMACs.

Definition at line 882 of file buffer.h.

References BPTR, buf_string_compare_advance(), buf_string_match_head_str(), buf_substring_len(), buffer::len, match(), and np().

Referenced by is_occ_msg().

◆ buf_string_match_head_str()

bool buf_string_match_head_str ( const struct buffer src,
const char *  match 
)

◆ buf_sub()

struct buffer buf_sub ( struct buffer buf,
int  size,
bool  prepend 
)

◆ buf_substring_len()

int buf_substring_len ( const struct buffer buf,
int  delim 
)

Definition at line 843 of file buffer.c.

References buf_read_u8().

Referenced by buf_string_match_head(), and command_line_get().

◆ buf_valid()

static bool buf_valid ( const struct buffer buf)
inlinestatic

◆ buf_write()

static bool buf_write ( struct buffer dest,
const void *  src,
int  size 
)
inlinestatic

◆ buf_write_alloc()

static uint8_t* buf_write_alloc ( struct buffer buf,
int  size 
)
inlinestatic

◆ buf_write_alloc_prepend()

static uint8_t* buf_write_alloc_prepend ( struct buffer buf,
int  size,
bool  prepend 
)
inlinestatic

Definition at line 668 of file buffer.h.

References buf_prepend(), and buf_write_alloc().

◆ buf_write_prepend()

static bool buf_write_prepend ( struct buffer dest,
const void *  src,
int  size 
)
inlinestatic

◆ buf_write_u16()

static bool buf_write_u16 ( struct buffer dest,
int  data 
)
inlinestatic

◆ buf_write_u32()

static bool buf_write_u32 ( struct buffer dest,
int  data 
)
inlinestatic

Definition at line 726 of file buffer.h.

References buf_write().

Referenced by build_dhcp_options_string(), key_method_2_write(), and write_dhcp_u32_array().

◆ buf_write_u8()

static bool buf_write_u8 ( struct buffer dest,
int  data 
)
inlinestatic

◆ buffer_list_advance()

void buffer_list_advance ( struct buffer_list ol,
int  n 
)

Definition at line 1365 of file buffer.c.

References ASSERT, BLEN, buffer_entry::buf, buf_advance(), buffer_list_pop(), and buffer_list::head.

Referenced by init_static(), and man_write().

◆ buffer_list_aggregate()

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.

Parameters
blthe list of buffer to aggregate
maxthe maximum length of the aggregated buffer

Definition at line 1342 of file buffer.c.

References buffer_list_aggregate_separator().

Referenced by init_static(), man_write(), and management_query_multiline_flatten().

◆ buffer_list_aggregate_separator()

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.

Parameters
blthe list of buffer to aggregate
max_lenthe maximum length of the aggregated buffer
septhe separator to put between buffers during aggregation

Definition at line 1296 of file buffer.c.

References alloc_buf(), ALLOC_OBJ_CLEAR, BLEN, buffer_entry::buf, buf_copy(), buf_write(), http-client::f, free, free_buf(), buffer_list::head, 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().

◆ buffer_list_defined()

bool buffer_list_defined ( const struct buffer_list ol)

Checks if the list is valid and non-empty.

Parameters
olthe list to check
Returns
true iff ol is not NULL and contains at least one buffer

Definition at line 1221 of file buffer.c.

References buffer_list::head.

Referenced by man_update_io_state(), management_query_multiline_flatten(), and management_query_multiline_flatten_newline().

◆ buffer_list_file()

struct buffer_list* buffer_list_file ( const char *  fn,
int  max_line_len 
)

Definition at line 1379 of file buffer.c.

References buffer_list_new(), buffer_list_push(), free, malloc, and platform_fopen().

◆ buffer_list_free()

void buffer_list_free ( struct buffer_list ol)

◆ buffer_list_new()

struct buffer_list* buffer_list_new ( const int  max_size)

Allocate an empty buffer list of capacity max_size.

Parameters
max_sizethe capacity of the list to allocate
Returns
the new list

Definition at line 1201 of file buffer.c.

References ALLOC_OBJ_CLEAR, buffer_list::max_size, and buffer_list::size.

Referenced by buffer_list_file(), in_extra_reset(), init_static(), man_connection_init(), test_buffer_list_setup(), and tls_send_payload().

◆ buffer_list_peek()

struct buffer* buffer_list_peek ( struct buffer_list ol)

◆ buffer_list_pop()

void buffer_list_pop ( struct buffer_list ol)

◆ buffer_list_push()

void buffer_list_push ( struct buffer_list ol,
const char *  str 
)

Allocates and appends a new buffer containing str as data to ol.

Parameters
olthe list to append the new buffer to
strthe string to copy into the new buffer

Definition at line 1242 of file buffer.c.

References buffer_entry::buf, buffer_list_push_data(), and buffer::len.

Referenced by buffer_list_file(), init_static(), man_output_list_push_str(), man_read(), test_buffer_list_full(), and test_buffer_list_setup().

◆ buffer_list_push_data()

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.

Parameters
olthe list to append the new buffer to
datathe data to copy into the new buffer
sizethe length of data to copy into the buffer
Returns
the new buffer

Definition at line 1256 of file buffer.c.

References alloc_buf(), ALLOC_OBJ_CLEAR, ASSERT, buffer_entry::buf, buffer::data, buffer_list::head, buffer::len, buffer_list::max_size, buffer_entry::next, buffer_list::size, and buffer_list::tail.

Referenced by buffer_list_push(), test_buffer_list_setup(), and tls_send_payload().

◆ buffer_list_reset()

void buffer_list_reset ( struct buffer_list ol)

Empty the list ol and frees all the contained buffers.

Parameters
olthe list to reset

Definition at line 1227 of file buffer.c.

References buffer_entry::buf, free, 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()

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

Parameters
filepath to the file to read
gcthe garbage collector to use when allocating the buffer. It is passed to alloc_buf_gc() and therefore can be NULL.
Returns
the buffer storing the file content or an invalid buffer in case of error

Definition at line 1402 of file buffer.c.

References alloc_buf_gc(), ASSERT, BPTR, buf_inc_len(), buf_null_terminate(), free_buf_gc(), platform_fopen(), platform_stat(), and ssize_t.

Referenced by options_postprocess_mutate_ce(), read_key_file(), and tls_crypt_v2_read_keyfile().

◆ buffer_write_file()

bool buffer_write_file ( const char *  filename,
const struct buffer buf 
)

Write buffer contents to file.

Parameters
filenameThe filename to write the buffer to.
bufThe buffer to write to the file.
Returns
true on success, false otherwise.

Definition at line 372 of file buffer.c.

References BLEN, BPTR, M_ERRNO, msg, platform_open(), S_IRUSR, S_IWUSR, and write.

Referenced by secure_memzero(), tls_crypt_v2_verify_metadata(), tls_crypt_v2_write_client_key_file(), tls_crypt_v2_write_server_key_file(), and write_key_file().

◆ char_class()

bool char_class ( const unsigned char  c,
const unsigned int  flags 
)

◆ check_malloc_return()

static void check_malloc_return ( const void *  p)
inlinestatic

◆ chomp()

void chomp ( char *  str)

◆ clear_buf()

static struct buffer clear_buf ( void  )
static

◆ clone_buf()

struct buffer clone_buf ( const struct buffer buf)

◆ convert_to_one_line()

void convert_to_one_line ( struct buffer buf)

Definition at line 357 of file buffer.c.

References BLEN, BPTR, and buffer::len.

Referenced by secure_memzero().

◆ format_hex()

static char* format_hex ( const uint8_t data,
int  size,
int  maxoutput,
struct gc_arena gc 
)
inlinestatic

◆ format_hex_ex()

char* format_hex_ex ( const uint8_t data,
int  size,
int  maxoutput,
unsigned int  space_break_flags,
const char *  separator,
struct gc_arena gc 
)

◆ free_buf()

void free_buf ( struct buffer buf)

◆ gc_addspecial()

void gc_addspecial ( void *  addr,
void(*)(void *)  free_function,
struct gc_arena a 
)

◆ gc_defined()

static bool gc_defined ( struct gc_arena a)
inlinestatic

Definition at line 995 of file buffer.h.

References gc_arena::list.

◆ gc_detach()

static void gc_detach ( struct gc_arena a)
inlinestatic

Definition at line 1008 of file buffer.h.

References gc_init().

Referenced by inherit_context_top(), and options_detach().

◆ gc_free()

static void gc_free ( struct gc_arena a)
inlinestatic

Definition at line 1022 of file buffer.h.

References gc_arena::list, gc_arena::list_special, x_gc_free(), and x_gc_freespecial().

Referenced by adapter_index_of_ip(), add_option(), add_route(), add_route_ipapi(), add_route_ipv6(), argv_msg(), argv_msg_prefix(), argv_parse_cmd(), argv_str__multiple_argv__correct_output(), block_dns_msg_handler(), ce_management_query_proxy(), ce_management_query_remote(), check_addr_clash(), check_file_access_chroot(), check_incoming_control_channel_dowork(), check_ping_restart_dowork(), check_stale_routes(), check_subnet_conflict(), clear_route_ipv6_list(), clear_route_list(), close_instance(), close_tun(), context_gc_free(), crypto_pem_encode_decode_loopback(), del_route_ipapi(), delete_route(), delete_route_ipv6(), delete_temp_addresses(), dhcp_extract_router_msg(), dhcp_masq_addr(), dhcp_release_by_adapter_index(), dhcp_renew_by_adapter_index(), dhcp_status(), do_address_service(), do_close_tun(), do_compute_occ_strings(), do_dns6_service(), do_ifconfig_ipv4(), do_ifconfig_ipv6(), do_ifconfig_setenv(), do_open_tun(), do_route_service(), drop_if_recursive_routing(), establish_http_proxy_passthru(), fixup_key(), foreign_option(), fork_dhcp_action(), fork_register_dns_action(), frame_print(), gc_reset(), generate_key_random(), generate_prefix(), get_adapter_index_flexible(), get_adapter_index_method_2(), get_bypass_addresses(), get_default_gateway(), get_default_gateway_ipv6(), get_default_gateway_row(), get_user_pass_cr(), hash_iterator_delete_element(), helper_client_server(), ifconfig_pool_init(), ifconfig_pool_list(), ifconfig_pool_read(), ifconfig_pool_verify_range(), ifconfig_pool_write(), ifconfig_sanity_check(), incoming_push_message(), init_key_ctx(), init_route_ipv6_list(), init_route_list(), init_static(), init_tun(), ip_addr_string_to_array(), key2_print(), key_method_2_read(), key_source_print(), key_state_export_keying_material(), learn_address_script(), link_socket_bad_incoming_addr(), link_socket_connection_initiated(), linksock_print_addr(), man_connect(), man_dispatch_command(), man_history(), man_io_error(), man_kill(), man_listen(), man_new_connection_post(), man_output_extra_env(), man_process_command(), man_record_peer_info(), management_echo(), management_hold(), management_notify_generic(), management_query_multiline(), management_query_user_pass(), management_set_state(), mroute_extract_addr_ip(), mroute_helper_regenerate(), multi_add_iroutes(), multi_bcast(), multi_client_connect_setenv(), multi_connection_established(), multi_create_instance(), multi_create_instance_tcp(), multi_get_create_instance_udp(), multi_get_instance_by_virtual_addr(), multi_instance_dec_refcount(), multi_learn_addr(), multi_print_status(), multi_process_float(), multi_process_incoming_link(), multi_process_incoming_tun(), multi_reap_range(), multi_select_virtual_addr(), multi_tcp_post(), netsh_ifconfig(), netsh_ifconfig_options(), netsh_set_dns6_servers(), open_null(), open_tun(), openvpn_decrypt_aead(), openvpn_decrypt_v1(), openvpn_encrypt_aead(), openvpn_encrypt_v1(), openvpn_execve(), openvpn_execve_allowed(), openvpn_execve_check(), openvpn_getaddrinfo(), openvpn_popen(), options_cmp_equal_safe(), options_warning_extract_parm1(), options_warning_safe_ml(), options_warning_safe_scan1(), options_warning_safe_scan2(), packet_id_persist_load(), packet_id_persist_print(), packet_id_persist_save(), platform_access(), platform_chdir(), platform_fopen(), platform_open(), platform_stat(), platform_unlink(), plugin_call_item(), plugin_call_ssl(), plugin_common_open(), plugin_init_item(), plugin_open_item(), plugin_option_list_print(), plugin_vlog(), print_client_nat_list(), print_default_gateway(), print_pkt(), print_route(), print_status(), process_incoming_link_part1(), process_incoming_push_request(), process_incoming_tun(), process_outgoing_link(), process_outgoing_tun(), push_peer_info(), read_control_auth(), read_key_file(), redirect_stdout_stderr(), register_dns_service(), reliable_ack_read(), reliable_can_get(), reliable_can_send(), reliable_get_buf_output_sequenced(), reliable_not_replay(), reliable_send_timeout(), reliable_wont_break_sequentiality(), remove_iroutes_from_push_route_list(), resolve_bind_local(), resolve_remote(), route_quota_exceeded(), run_up_down(), schedule_remove_entry(), sd_close(), send_auth_failed(), send_control_channel_string(), send_msg_iservice(), send_push_reply(), service_enable_dhcp(), setenv_int_i(), setenv_route(), setenv_route_addr(), setenv_route_ipv6(), setenv_str_ex(), setenv_str_i(), show_adapters(), show_dhcp_option_addrs(), show_p2mp_parms(), show_routes(), show_tap_win_adapters(), show_windows_version(), socket_bind(), socket_connect(), socket_do_listen(), socket_listen_accept(), socket_recv_queue(), socket_send_queue(), tap_allow_nonadmin_access(), tcp_connection_established(), test_buffer_free_gc_one(), test_buffer_free_gc_two(), test_crypto(), test_local_addr(), test_routes(), test_tls_crypt_v2_teardown(), tls1_P_hash(), tls1_PRF(), tls_crypt_unwrap(), tls_crypt_v2_read_keyfile(), tls_crypt_v2_unwrap_client_key(), tls_crypt_v2_verify_metadata(), tls_crypt_v2_write_client_key_file(), tls_crypt_v2_write_server_key_file(), tls_crypt_wrap(), tls_ctx_load_extra_certs(), tls_ctx_use_external_rsa_key(), tls_multi_process(), tls_pre_decrypt(), tls_pre_decrypt_lite(), tls_pre_encrypt(), tls_process(), tls_session_init(), tls_update_remote_addr(), tun_read_queue(), tun_write_queue(), uninit_options(), verify_255_255_255_252(), verify_callback(), verify_cert(), verify_cert_call_command(), verify_cert_set_env(), verify_check_crl_dir(), verify_common_subnet(), verify_final_auth_checks(), verify_user_pass(), verify_user_pass_script(), virtual_output_callback_func(), warn_on_use_of_common_subnets(), win_block_dns_service(), window_title_generate(), windows_route_find_if_index(), write_key_file(), x509_setenv_track(), x_check_status(), and x_msg_va().

◆ gc_freeaddrinfo_callback()

static void gc_freeaddrinfo_callback ( void *  addr)
inlinestatic

Definition at line 202 of file buffer.h.

Referenced by do_preresolve_host(), and init_route_list().

◆ gc_init()

static void gc_init ( struct gc_arena a)
inlinestatic

◆ gc_malloc()

void* gc_malloc ( size_t  size,
bool  clear,
struct gc_arena a 
)

◆ gc_new()

static struct gc_arena gc_new ( void  )
static

Definition at line 1014 of file buffer.h.

References gc_init().

Referenced by adapter_index_of_ip(), add_option(), add_route_ipapi(), argv_msg(), argv_msg_prefix(), argv_parse_cmd(), argv_str__multiple_argv__correct_output(), block_dns_msg_handler(), ce_management_query_proxy(), ce_management_query_remote(), check_addr_clash(), check_file_access_chroot(), check_incoming_control_channel_dowork(), check_ping_restart_dowork(), check_stale_routes(), check_subnet_conflict(), close_tun(), crypto_pem_encode_decode_loopback(), del_route_ipapi(), delete_temp_addresses(), dhcp_extract_router_msg(), dhcp_masq_addr(), dhcp_release_by_adapter_index(), dhcp_renew_by_adapter_index(), dhcp_status(), do_address_service(), do_close_tun(), do_compute_occ_strings(), do_dns6_service(), do_ifconfig_ipv4(), do_ifconfig_ipv6(), do_ifconfig_setenv(), do_open_tun(), do_route_service(), drop_if_recursive_routing(), establish_http_proxy_passthru(), fixup_key(), foreign_option(), fork_dhcp_action(), fork_register_dns_action(), frame_print(), generate_key_random(), generate_prefix(), get_adapter_index_flexible(), get_adapter_index_method_2(), get_bypass_addresses(), get_default_gateway(), get_default_gateway_ipv6(), get_default_gateway_row(), get_user_pass_cr(), hash_iterator_delete_element(), helper_client_server(), ifconfig_pool_init(), ifconfig_pool_list(), ifconfig_pool_read(), ifconfig_pool_verify_range(), ifconfig_pool_write(), ifconfig_sanity_check(), incoming_push_message(), inherit_context_child(), init_key_ctx(), init_route_ipv6_list(), init_route_list(), init_static(), init_tun(), ip_addr_string_to_array(), key2_print(), key_method_2_read(), key_source_print(), key_state_export_keying_material(), learn_address_script(), link_socket_bad_incoming_addr(), link_socket_connection_initiated(), linksock_print_addr(), man_connect(), man_dispatch_command(), man_history(), man_io_error(), man_kill(), man_listen(), man_new_connection_post(), man_output_extra_env(), man_process_command(), man_record_peer_info(), management_echo(), management_hold(), management_notify_generic(), management_query_multiline(), management_query_user_pass(), management_set_state(), mroute_extract_addr_ip(), mroute_helper_regenerate(), multi_add_iroutes(), multi_bcast(), multi_client_connect_setenv(), multi_connection_established(), multi_create_instance(), multi_create_instance_tcp(), multi_get_create_instance_udp(), multi_get_instance_by_virtual_addr(), multi_learn_addr(), multi_print_status(), multi_process_float(), multi_process_incoming_link(), multi_process_incoming_tun(), multi_reap_range(), multi_select_virtual_addr(), multi_tcp_post(), netsh_ifconfig(), netsh_ifconfig_options(), netsh_set_dns6_servers(), open_null(), open_tun(), openvpn_execve(), openvpn_execve_allowed(), openvpn_execve_check(), openvpn_getaddrinfo(), openvpn_popen(), options_cmp_equal_safe(), options_warning_extract_parm1(), options_warning_safe_ml(), options_warning_safe_scan1(), options_warning_safe_scan2(), packet_id_persist_load(), packet_id_persist_print(), packet_id_persist_save(), platform_access(), platform_chdir(), platform_fopen(), platform_open(), platform_stat(), platform_unlink(), plugin_call_item(), plugin_call_ssl(), plugin_common_open(), plugin_init_item(), plugin_open_item(), plugin_option_list_print(), print_client_nat_list(), print_default_gateway(), print_pkt(), print_route(), print_status(), process_incoming_link_part1(), process_incoming_push_request(), process_incoming_tun(), process_outgoing_link(), process_outgoing_tun(), push_peer_info(), read_control_auth(), read_key_file(), redirect_stdout_stderr(), register_dns_service(), reliable_ack_read(), reliable_can_get(), reliable_can_send(), reliable_get_buf_output_sequenced(), reliable_not_replay(), reliable_send_timeout(), reliable_wont_break_sequentiality(), remove_iroutes_from_push_route_list(), resolve_bind_local(), resolve_remote(), route_quota_exceeded(), run_up_down(), schedule_remove_entry(), sd_close(), send_auth_failed(), send_control_channel_string(), send_msg_iservice(), send_push_reply(), service_enable_dhcp(), setenv_int_i(), setenv_route(), setenv_route_addr(), setenv_route_ipv6(), setenv_str_ex(), setenv_str_i(), show_adapters(), show_dhcp_option_addrs(), show_p2mp_parms(), show_routes(), show_tap_win_adapters(), show_windows_version(), socket_bind(), socket_connect(), socket_do_listen(), socket_listen_accept(), socket_recv_queue(), socket_send_queue(), tap_allow_nonadmin_access(), tcp_connection_established(), test_buffer_free_gc_one(), test_buffer_free_gc_two(), test_crypto(), test_local_addr(), test_routes(), test_tls_crypt_v2_setup(), tls1_P_hash(), tls1_PRF(), tls_crypt_v2_read_keyfile(), tls_crypt_v2_unwrap_client_key(), tls_crypt_v2_verify_metadata(), tls_crypt_v2_write_client_key_file(), tls_crypt_v2_write_server_key_file(), tls_ctx_load_extra_certs(), tls_ctx_use_external_rsa_key(), tls_multi_process(), tls_pre_decrypt(), tls_pre_decrypt_lite(), tls_pre_encrypt(), tls_process(), tls_session_init(), tls_update_remote_addr(), tun_read_queue(), tun_write_queue(), verify_255_255_255_252(), verify_callback(), verify_cert(), verify_cert_call_command(), verify_cert_set_env(), verify_check_crl_dir(), verify_common_subnet(), verify_final_auth_checks(), verify_user_pass(), verify_user_pass_script(), virtual_output_callback_func(), warn_on_use_of_common_subnets(), win_block_dns_service(), window_title_generate(), windows_route_find_if_index(), write_key_file(), x509_setenv_track(), and x_check_status().

◆ gc_reset()

static void gc_reset ( struct gc_arena a)
inlinestatic

Definition at line 1035 of file buffer.h.

References gc_free().

Referenced by openvpn_main().

◆ gc_transfer()

void gc_transfer ( struct gc_arena dest,
struct gc_arena src 
)

Definition at line 499 of file buffer.c.

References gc_arena::list, and gc_entry::next.

Referenced by add_option().

◆ has_digit()

static bool has_digit ( const unsigned char *  src)
inlinestatic

Definition at line 359 of file buffer.h.

Referenced by open_null().

◆ np()

const char* np ( const char *  str)

Definition at line 900 of file buffer.c.

Referenced by buf_string_match_head().

◆ openvpn_snprintf()

bool openvpn_snprintf ( char *  str,
size_t  size,
const char *  format,
  ... 
)

◆ openvpn_swprintf()

bool openvpn_swprintf ( wchar_t *const  str,
const size_t  size,
const wchar_t *const  format,
  ... 
)

Definition at line 321 of file buffer.c.

Referenced by secure_memzero().

◆ print_argv()

char* print_argv ( const char **  p,
struct gc_arena gc,
const unsigned int  flags 
)

Definition at line 757 of file buffer.c.

References alloc_buf_gc(), BSTR, buf_printf(), and PA_BRACKET.

Referenced by argv_str(), plugin_open_item(), plugin_option_list_print(), and push_options().

◆ rm_trailing_chars()

void rm_trailing_chars ( char *  str,
const char *  what_to_delete 
)

Definition at line 662 of file buffer.c.

References buffer::len.

Referenced by chomp(), and secure_memzero().

◆ secure_memzero()

static void secure_memzero ( void *  data,
size_t  len 
)
inlinestatic

Securely zeroise memory.

This code and description are based on code supplied by Zhaomo Yang, of the University of California, San Diego (which was released into the public domain).

The secure_memzero function attempts to ensure that an optimizing compiler does not remove the intended operation if cleared memory is not accessed again by the program. This code has been tested under Clang 3.9.0 and GCC 6.2 with optimization flags -O, -Os, -O0, -O1, -O2, and -O3 on Ubuntu 16.04.1 LTS; under Clang 3.9.0 with optimization flags -O, -Os, -O0, -O1, -O2, and -O3 on FreeBSD 10.2-RELEASE; under Microsoft Visual Studio 2015 with optimization flags /O1, /O2 and /Ox on Windows 10.

Theory of operation:

  1. On Windows, use the SecureZeroMemory which ensures that data is overwritten.
  2. Under GCC or Clang, use a memory barrier, which forces the preceding memset to be carried out. The overhead of a memory barrier is usually negligible.
  3. If none of the above are available, use the volatile pointer technique to zero memory one byte at a time.
Parameters
dataPointer to data to zeroise.
lenLength of data, in bytes.

Definition at line 401 of file buffer.h.

References buf_catrunc(), buf_chomp(), buf_null_terminate(), buf_parse(), buf_printf(), buf_puts(), buf_rmtail(), buffer_write_file(), buffer::capacity, chomp(), convert_to_one_line(), buffer::len, openvpn_snprintf(), openvpn_swprintf(), rm_trailing_chars(), skip_leading_whitespace(), and string_null_terminate().

Referenced by buf_clear(), crypto_read_openvpn_key(), generate_key_expansion(), get_console_input(), key_method_1_read(), key_method_1_write(), key_method_2_read(), key_method_2_write(), key_state_free(), management_query_user_pass(), move_session(), purge_user_pass(), read_config_file(), read_config_string(), read_inline_file(), remove_env_item(), string_clear(), tls1_P_hash(), tls1_PRF(), tls_crypt_v2_extract_client_key(), tls_crypt_v2_init_client_key(), tls_crypt_v2_init_server_key(), tls_crypt_v2_unwrap_client_key(), tls_crypt_v2_write_client_key_file(), tls_crypt_v2_write_server_key_file(), tls_multi_free(), tls_session_free(), tls_session_generate_data_channel_keys(), wipe_auth_token(), and write_key_file().

◆ skip_leading_whitespace()

const char* skip_leading_whitespace ( const char *  str)

Definition at line 618 of file buffer.c.

Referenced by make_inline_array(), and secure_memzero().

◆ string_alloc()

char* string_alloc ( const char *  str,
struct gc_arena gc 
)

◆ string_alloc_buf()

struct buffer string_alloc_buf ( const char *  str,
struct gc_arena gc 
)

Definition at line 792 of file buffer.c.

References ASSERT, buf_set_read(), buffer::len, and string_alloc().

Referenced by options_warning_extract_parm1().

◆ string_array_len()

int string_array_len ( const char **  array)

◆ string_class()

bool string_class ( const char *  str,
const unsigned int  inclusive,
const unsigned int  exclusive 
)

Definition at line 1062 of file buffer.c.

References ASSERT, and char_inc_exc().

Referenced by dns_addr_safe(), openvpn_inet_aton(), push_option_ex(), and wide_cmd_line().

◆ string_clear()

void string_clear ( char *  str)

◆ string_mod()

bool string_mod ( char *  str,
const unsigned int  inclusive,
const unsigned int  exclusive,
const char  replace 
)

◆ string_mod_const()

const char* string_mod_const ( const char *  str,
const unsigned int  inclusive,
const unsigned int  exclusive,
const char  replace,
struct gc_arena gc 
)

Definition at line 1113 of file buffer.c.

References string_alloc(), and string_mod().

Referenced by platform_gen_path(), safe_print(), and setenv_str_ex().

◆ string_null_terminate()

void string_null_terminate ( char *  str,
int  len,
int  capacity 
)

Definition at line 636 of file buffer.c.

References ASSERT, and buffer::len.

Referenced by get_console_input_win32(), and secure_memzero().

◆ string_replace_leading()

void string_replace_leading ( char *  str,
const char  match,
const char  replace 
)

◆ strncpynt()

static void strncpynt ( char *  dest,
const char *  src,
size_t  maxlen 
)
inlinestatic

◆ strprefix()

static bool strprefix ( const char *  str,
const char *  prefix 
)
inlinestatic

Return true iff str starts with prefix.

Definition at line 961 of file buffer.h.

Referenced by options_warning_safe_scan2(), push_update_digest(), and test_buffer_strprefix().

◆ x_gc_free()

void x_gc_free ( struct gc_arena a)

Definition at line 442 of file buffer.c.

References free, gc_arena::list, and gc_entry::next.

Referenced by gc_free().

◆ x_gc_freespecial()

void x_gc_freespecial ( struct gc_arena a)