OpenVPN
Data Structures | Macros | Functions
buffer.h File Reference
#include "basic.h"
#include "error.h"
Include dependency graph for buffer.h:

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)
 any character More...
 
#define CC_NULL   (1<<1)
 null character \0 More...
 
#define CC_ALNUM   (1<<2)
 alphanumeric isalnum() More...
 
#define CC_ALPHA   (1<<3)
 alphabetic isalpha() More...
 
#define CC_ASCII   (1<<4)
 ASCII character. More...
 
#define CC_CNTRL   (1<<5)
 control character iscntrl() More...
 
#define CC_DIGIT   (1<<6)
 digit isdigit() More...
 
#define CC_PRINT   (1<<7)
 printable (>= 32, != 127) More...
 
#define CC_PUNCT   (1<<8)
 punctuation ispunct() More...
 
#define CC_SPACE   (1<<9)
 whitespace isspace() More...
 
#define CC_XDIGIT   (1<<10)
 hex digit isxdigit() More...
 
#define CC_BLANK   (1<<11)
 space or tab More...
 
#define CC_NEWLINE   (1<<12)
 newline More...
 
#define CC_CR   (1<<13)
 carriage return More...
 
#define CC_BACKSLASH   (1<<14)
 backslash More...
 
#define CC_UNDERBAR   (1<<15)
 underscore More...
 
#define CC_DASH   (1<<16)
 dash More...
 
#define CC_DOT   (1<<17)
 dot More...
 
#define CC_COMMA   (1<<18)
 comma More...
 
#define CC_COLON   (1<<19)
 colon More...
 
#define CC_SLASH   (1<<20)
 slash More...
 
#define CC_SINGLE_QUOTE   (1<<21)
 single quote More...
 
#define CC_DOUBLE_QUOTE   (1<<22)
 double quote More...
 
#define CC_REVERSE_QUOTE   (1<<23)
 reverse quote More...
 
#define CC_AT   (1<<24)
 at sign More...
 
#define CC_EQUAL   (1<<25)
 equal sign More...
 
#define CC_LESS_THAN   (1<<26)
 less than sign More...
 
#define CC_GREATER_THAN   (1<<27)
 greater than sign More...
 
#define CC_PIPE   (1<<28)
 pipe More...
 
#define CC_QUESTION_MARK   (1<<29)
 question mark More...
 
#define CC_ASTERISK   (1<<30)
 asterisk More...
 
#define CC_NAME   (CC_ALNUM|CC_UNDERBAR)
 alphanumeric plus underscore More...
 
#define CC_CRLF   (CC_CR|CC_NEWLINE)
 carriage return or newline More...
 
#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)
 
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 More...
 
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_t * buf_bptr (const struct buffer *buf)
 
static int buf_len (const struct buffer *buf)
 
static uint8_t * buf_bend (const struct buffer *buf)
 
static uint8_t * buf_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, size_t size)
 
static void strncpynt (char *dest, const char *src, size_t maxlen)
 
static bool has_digit (const 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,...)
 
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, size_t 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_t * buf_prepend (struct buffer *buf, int size)
 
static bool buf_advance (struct buffer *buf, int size)
 
static uint8_t * buf_write_alloc (struct buffer *buf, size_t size)
 
static uint8_t * buf_write_alloc_prepend (struct buffer *buf, int size, bool prepend)
 
static uint8_t * buf_read_alloc (struct buffer *buf, int size)
 
static bool buf_write (struct buffer *dest, const void *src, size_t size)
 
static bool buf_write_prepend (struct buffer *dest, const void *src, int size)
 
static bool buf_write_u8 (struct buffer *dest, uint8_t data)
 
static bool buf_write_u16 (struct buffer *dest, uint16_t data)
 
static bool buf_write_u32 (struct buffer *dest, uint32_t 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)
 Modifies a string in place by replacing certain classes of characters of it with a specified character. More...
 
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. More...
 
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 (void *p)
 
struct buffer_listbuffer_list_new (void)
 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))); \
}

Definition at line 1072 of file buffer.h.

◆ 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))); \
}

Definition at line 1082 of file buffer.h.

◆ 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)); \
}

Definition at line 1088 of file buffer.h.

◆ 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)); \
}

Definition at line 1077 of file buffer.h.

◆ ALLOC_OBJ

#define ALLOC_OBJ (   dptr,
  type 
)
Value:
{ \
check_malloc_return((dptr) = (type *) malloc(sizeof(type))); \
}

Definition at line 1061 of file buffer.h.

◆ ALLOC_OBJ_CLEAR

#define ALLOC_OBJ_CLEAR (   dptr,
  type 
)
Value:
{ \
ALLOC_OBJ(dptr, type); \
memset((dptr), 0, sizeof(type)); \
}

Definition at line 1066 of file buffer.h.

◆ ALLOC_OBJ_CLEAR_GC

#define ALLOC_OBJ_CLEAR_GC (   dptr,
  type,
  gc 
)
Value:
{ \
(dptr) = (type *) gc_malloc(sizeof(type), true, (gc)); \
}

Definition at line 1103 of file buffer.h.

◆ ALLOC_OBJ_GC

#define ALLOC_OBJ_GC (   dptr,
  type,
  gc 
)
Value:
{ \
(dptr) = (type *) gc_malloc(sizeof(type), false, (gc)); \
}

Definition at line 1098 of file buffer.h.

◆ 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)); \
}

Definition at line 1093 of file buffer.h.

◆ BCAP

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

Definition at line 130 of file buffer.h.

◆ BDEF

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

Definition at line 128 of file buffer.h.

◆ BEND

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

Definition at line 125 of file buffer.h.

◆ BLAST

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

Definition at line 126 of file buffer.h.

◆ BLEN

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

Definition at line 127 of file buffer.h.

◆ BPTR

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

Definition at line 124 of file buffer.h.

◆ BSTR

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

Definition at line 129 of file buffer.h.

◆ buf_init

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

Definition at line 209 of file buffer.h.

◆ BUF_SIZE_MAX

#define BUF_SIZE_MAX   1000000

Definition at line 30 of file buffer.h.

◆ CC_ALNUM

#define CC_ALNUM   (1<<2)

alphanumeric isalnum()

Definition at line 904 of file buffer.h.

◆ CC_ALPHA

#define CC_ALPHA   (1<<3)

alphabetic isalpha()

Definition at line 905 of file buffer.h.

◆ CC_ANY

#define CC_ANY   (1<<0)

any character

Definition at line 901 of file buffer.h.

◆ CC_ASCII

#define CC_ASCII   (1<<4)

ASCII character.

Definition at line 906 of file buffer.h.

◆ CC_ASTERISK

#define CC_ASTERISK   (1<<30)

asterisk

Definition at line 934 of file buffer.h.

◆ CC_AT

#define CC_AT   (1<<24)

at sign

Definition at line 928 of file buffer.h.

◆ CC_BACKSLASH

#define CC_BACKSLASH   (1<<14)

backslash

Definition at line 918 of file buffer.h.

◆ CC_BLANK

#define CC_BLANK   (1<<11)

space or tab

Definition at line 914 of file buffer.h.

◆ CC_CNTRL

#define CC_CNTRL   (1<<5)

control character iscntrl()

Definition at line 907 of file buffer.h.

◆ CC_COLON

#define CC_COLON   (1<<19)

colon

Definition at line 923 of file buffer.h.

◆ CC_COMMA

#define CC_COMMA   (1<<18)

comma

Definition at line 922 of file buffer.h.

◆ CC_CR

#define CC_CR   (1<<13)

carriage return

Definition at line 916 of file buffer.h.

◆ CC_CRLF

#define CC_CRLF   (CC_CR|CC_NEWLINE)

carriage return or newline

Definition at line 938 of file buffer.h.

◆ CC_DASH

#define CC_DASH   (1<<16)

dash

Definition at line 920 of file buffer.h.

◆ CC_DIGIT

#define CC_DIGIT   (1<<6)

digit isdigit()

Definition at line 908 of file buffer.h.

◆ CC_DOT

#define CC_DOT   (1<<17)

dot

Definition at line 921 of file buffer.h.

◆ CC_DOUBLE_QUOTE

#define CC_DOUBLE_QUOTE   (1<<22)

double quote

Definition at line 926 of file buffer.h.

◆ CC_EQUAL

#define CC_EQUAL   (1<<25)

equal sign

Definition at line 929 of file buffer.h.

◆ CC_GREATER_THAN

#define CC_GREATER_THAN   (1<<27)

greater than sign

Definition at line 931 of file buffer.h.

◆ CC_LESS_THAN

#define CC_LESS_THAN   (1<<26)

less than sign

Definition at line 930 of file buffer.h.

◆ CC_NAME

#define CC_NAME   (CC_ALNUM|CC_UNDERBAR)

alphanumeric plus underscore

Definition at line 937 of file buffer.h.

◆ CC_NEWLINE

#define CC_NEWLINE   (1<<12)

newline

Definition at line 915 of file buffer.h.

◆ CC_NULL

#define CC_NULL   (1<<1)

null character \0

Definition at line 902 of file buffer.h.

◆ CC_PIPE

#define CC_PIPE   (1<<28)

pipe

Definition at line 932 of file buffer.h.

◆ CC_PRINT

#define CC_PRINT   (1<<7)

printable (>= 32, != 127)

Definition at line 909 of file buffer.h.

◆ CC_PUNCT

#define CC_PUNCT   (1<<8)

punctuation ispunct()

Definition at line 910 of file buffer.h.

◆ CC_QUESTION_MARK

#define CC_QUESTION_MARK   (1<<29)

question mark

Definition at line 933 of file buffer.h.

◆ CC_REVERSE_QUOTE

#define CC_REVERSE_QUOTE   (1<<23)

reverse quote

Definition at line 927 of file buffer.h.

◆ CC_SINGLE_QUOTE

#define CC_SINGLE_QUOTE   (1<<21)

single quote

Definition at line 925 of file buffer.h.

◆ CC_SLASH

#define CC_SLASH   (1<<20)

slash

Definition at line 924 of file buffer.h.

◆ CC_SPACE

#define CC_SPACE   (1<<9)

whitespace isspace()

Definition at line 911 of file buffer.h.

◆ CC_UNDERBAR

#define CC_UNDERBAR   (1<<15)

underscore

Definition at line 919 of file buffer.h.

◆ CC_XDIGIT

#define CC_XDIGIT   (1<<10)

hex digit isxdigit()

Definition at line 912 of file buffer.h.

◆ FHE_CAPS

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

Definition at line 516 of file buffer.h.

◆ FHE_SPACE_BREAK_MASK

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

Definition at line 515 of file buffer.h.

◆ PA_BRACKET

#define PA_BRACKET   (1<<0)

Definition at line 144 of file buffer.h.

◆ verify_align_4

#define verify_align_4 (   ptr)

Definition at line 997 of file buffer.h.

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 88 of file buffer.c.

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

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(), crypto_pem_encode(), dco_version_string(), do_init_frame_tls(), 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(), netsh_get_id(), ntlm_phase_1(), options_string_compat_lzo(), options_string_version(), 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(), print_str_int(), proto2ascii_all(), protocol_dump(), push_peer_info(), read_control_auth(), reliable_ack_print(), route_string(), 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_free_gc_one(), test_buffer_free_gc_two(), test_buffer_printf_catrunc(), 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(), 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().

◆ array_mult_safe()

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

Definition at line 41 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 173 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 266 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 272 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)

◆ 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 771 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

◆ 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 747 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 855 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 577 of file buffer.h.

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

Referenced by buf_catrunc(), 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 319 of file buffer.h.

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

◆ buf_len()

static int buf_len ( const struct buffer buf)
static

◆ 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 240 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(), 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(), ntlm_phase_1(), 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(), print_str_int(), proto2ascii_all(), protocol_dump(), push_peer_info(), read_inline_file(), reliable_ack_print(), route_string(), 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(), 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().

◆ 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 672 of file buffer.h.

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

Referenced by buf_copy_n(), and buf_read().

◆ 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 832 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

◆ buf_reverse_capacity()

static int buf_reverse_capacity ( const struct buffer buf)
inlinestatic

Definition at line 595 of file buffer.h.

References buf_valid(), and buffer::offset.

Referenced by vlan_encapsulate().

◆ buf_rmtail()

void buf_rmtail ( struct buffer buf,
uint8_t  remove 
)

Definition at line 562 of file buffer.c.

References BLAST, and buffer::len.

◆ buf_safe()

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

◆ buf_safe_bidir()

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

Definition at line 545 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,
size_t  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 53 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 285 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 291 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 297 of file buffer.h.

References buf_bptr().

Referenced by mutate_ncp_cipher_list(), and prepare_push_reply().

◆ buf_string_compare_advance()

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

Definition at line 833 of file buffer.c.

References buf_advance(), and buf_string_match_head_str().

Referenced by process_incoming_push_msg(), and receive_auth_failed().

◆ 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 865 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 879 of file buffer.h.

References BPTR, and buffer::len.

Referenced by is_occ_msg().

◆ buf_string_match_head_str()

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

Definition at line 822 of file buffer.c.

References BPTR, and buffer::len.

Referenced by buf_string_compare_advance(), check_incoming_control_channel(), and receive_auth_failed().

◆ 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 847 of file buffer.c.

References buf_read_u8().

Referenced by 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,
size_t  size 
)
inlinestatic

◆ buf_write_alloc()

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

◆ buf_write_alloc_prepend()

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

Definition at line 666 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,
uint16_t  data 
)
inlinestatic

◆ buf_write_u32()

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

◆ buf_write_u8()

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

◆ buffer_list_advance()

void buffer_list_advance ( struct buffer_list ol,
int  n 
)

Definition at line 1348 of file buffer.c.

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

Referenced by 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 1325 of file buffer.c.

References buffer_list_aggregate_separator().

Referenced by 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 1279 of file buffer.c.

References alloc_buf(), ALLOC_OBJ_CLEAR, BLEN, buffer_entry::buf, buf_copy(), buf_write(), http-client::f, 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 1204 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 1362 of file buffer.c.

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

Referenced by key_state_check_auth_pending_file().

◆ buffer_list_free()

void buffer_list_free ( struct buffer_list ol)

◆ buffer_list_new()

struct buffer_list* buffer_list_new ( void  )

Allocate an empty buffer list of capacity max_size.

Returns
the new list

Definition at line 1185 of file buffer.c.

References ALLOC_OBJ_CLEAR, and buffer_list::size.

Referenced by buffer_list_file(), in_extra_reset(), 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 1225 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(), 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 1239 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().

◆ 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 1210 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()

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 1385 of file buffer.c.

References alloc_buf_gc(), ASSERT, BPTR, buf_inc_len(), buf_null_terminate(), cleanup(), free_buf_gc(), 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().

◆ 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 344 of file buffer.c.

References BLEN, BPTR, cleanup(), 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().

◆ char_class()

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

◆ check_malloc_return()

static void check_malloc_return ( void *  p)
inlinestatic

◆ chomp()

void chomp ( char *  str)

◆ clear_buf()

static struct buffer clear_buf ( void  )
inlinestatic

◆ 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 329 of file buffer.c.

References BLEN, BPTR, and buffer::len.

◆ 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 1012 of file buffer.h.

References gc_arena::list.

◆ gc_detach()

static void gc_detach ( struct gc_arena a)
inlinestatic

Definition at line 1025 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 1039 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_free(), argv_msg(), argv_msg_prefix(), argv_str__empty_argv__empty_output(), argv_str__multiple_argv__correct_output(), backend_x509_get_username(), block_dns_msg_handler(), ccs_gen_config_file(), ccs_gen_deferred_ret_file(), ce_management_query_proxy(), ce_management_query_remote(), check_addr_clash(), check_auth_pending_method(), check_file_access_chroot(), check_for_client_reason(), check_incoming_control_channel(), check_stale_routes(), check_subnet_conflict(), clear_route_ipv6_list(), clear_route_list(), close_instance(), close_tun(), context_gc_free(), crypto_pem_encode_certificate(), 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_dns_domain_service(), do_dns_service(), do_ifconfig_ipv4(), do_ifconfig_ipv6(), do_ifconfig_setenv(), do_open_tun(), do_pre_decrypt_check(), do_route_service(), do_set_mtu_service(), do_wins_service(), drop_if_recursive_routing(), establish_http_proxy_passthru(), export_user_keying_material(), fork_dhcp_action(), fork_register_dns_action(), frame_print(), gc_reset(), generate_auth_token(), generate_key_random(), generate_prefix(), get_adapter_index_method_2(), get_bypass_addresses(), get_default_gateway(), get_default_gateway_ipv6(), get_default_gateway_row(), get_p2p_ncp_cipher(), get_user_pass_cr(), handle_data_channel_packet(), helper_client_server(), ifconfig_pool_init(), ifconfig_pool_list(), ifconfig_pool_read(), ifconfig_pool_verify_range(), ifconfig_sanity_check(), incoming_push_message(), init_key_ctx(), init_route_ipv6_list(), init_route_list(), init_ssl(), init_static(), ip_addr_string_to_array(), key_method_2_read(), key_print(), key_source_print(), key_state_gen_auth_control_files(), 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(), management_callback_send_cc_message(), management_echo(), management_hold(), management_learn_addr(), management_notify_client_cr_response(), management_query_multiline(), management_query_user_pass(), management_set_state(), mroute_extract_addr_ip(), mroute_helper_regenerate(), multi_add_iroutes(), multi_client_connect_call_script(), multi_client_connect_late_setup(), multi_client_connect_setenv(), multi_client_connect_source_ccd(), multi_client_set_protocol_options(), 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_reap_range(), multi_select_virtual_addr(), multi_tcp_post(), ncp_get_best_cipher(), netsh_ifconfig(), netsh_ifconfig_options(), netsh_set_dns6_servers(), open_tun(), openvpn_decrypt_aead(), openvpn_decrypt_v1(), openvpn_encrypt_aead(), openvpn_encrypt_v1(), openvpn_execve(), 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(), p2p_mode_ncp(), packet_id_persist_load(), packet_id_persist_save(), parse_auth_failed_temp(), parse_hash_fingerprint_multiline(), 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(), pre_connect_restore(), print_client_nat_list(), print_default_gateway(), print_key_id_not_found_reason(), print_pkt(), print_route(), print_status(), process_incoming_link_part1(), process_incoming_push_request(), process_incoming_tun(), process_outgoing_link(), push_peer_info(), read_control_auth(), read_key_file(), read_pem_key_file(), recv_socks_reply(), redirect_stdout_stderr(), register_dns_service(), reliable_ack_read(), reliable_can_get(), reliable_can_send(), reliable_get_buf_output_sequenced(), reliable_get_num_output_sequenced_available(), reliable_not_replay(), reliable_send_timeout(), reliable_wont_break_sequentiality(), remove_iroutes_from_push_route_list(), resolve_bind_local(), resolve_remote(), route_ipv6_ipapi(), route_quota_exceeded(), run_up_down(), send_auth_failed(), send_auth_pending_messages(), send_control_channel_string_dowork(), send_msg_iservice(), send_push_reply(), send_push_reply_auth_token(), server_pushed_info(), service_enable_dhcp(), service_register_ring_buffers(), session_move_pre_start(), setenv_dns_options(), setenv_int_i(), setenv_route(), setenv_route_addr(), setenv_route_ipv6(), setenv_str_ex(), setenv_str_i(), show_adapters(), show_dco_version(), show_dhcp_option_addrs(), show_dns_options(), show_p2mp_parms(), show_routes(), show_settings(), show_tap_win_adapters(), show_windows_version(), socket_bind(), socket_connect(), socket_do_listen(), socket_listen_accept(), socket_recv_queue(), socket_send_queue(), ssl_tls1_PRF(), tap_allow_nonadmin_access(), tcp_connection_established(), test_buffer_format_hex_ex(), test_buffer_free_gc_one(), test_buffer_free_gc_two(), test_buffer_gc_realloc(), test_buffer_printf_catrunc(), test_check_ncp_ciphers_list(), test_cipher_names(), test_compat_lzo_string(), test_crypto(), test_extract_client_ciphers(), test_local_addr(), test_mssfix_mtu_calculation(), test_ncp_best(), test_occ_mtu_calculation(), test_poor_man(), test_routes(), test_tls_crypt_secure_reneg_key(), test_tls_crypt_v2_teardown(), tls_authentication_status(), tls_crypt_unwrap(), tls_crypt_v2_unwrap_client_key(), tls_crypt_v2_verify_metadata(), tls_crypt_v2_write_client_key_file(), tls_crypt_wrap(), tls_ctx_set_tls_groups(), tls_multi_process(), tls_pre_decrypt(), tls_pre_decrypt_lite(), tls_pre_encrypt(), tls_session_init(), tls_update_remote_addr(), trigger_ping_timeout_signal(), tun_read_queue(), tun_write_queue(), tuntap_dhcp_mask(), tuntap_set_ip_addr(), tuntap_set_ptp(), undo_ifconfig_ipv4(), undo_ifconfig_ipv6(), 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_crresponse_script(), verify_final_auth_checks(), verify_user_pass_script(), virtual_output_callback_func(), warn_on_use_of_common_subnets(), win32_signal_open(), win_block_dns_service(), window_title_generate(), windows_route_find_if_index(), write_key_file(), write_outgoing_tls_ciphertext(), write_pem_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 215 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  )
inlinestatic

Definition at line 1031 of file buffer.h.

References gc_init().

Referenced by adapter_index_of_ip(), add_option(), add_route(), add_route_ipapi(), add_route_ipv6(), argv_init(), argv_msg(), argv_msg_prefix(), argv_str__empty_argv__empty_output(), argv_str__multiple_argv__correct_output(), backend_x509_get_username(), block_dns_msg_handler(), ccs_gen_config_file(), ccs_gen_deferred_ret_file(), ce_management_query_proxy(), ce_management_query_remote(), check_addr_clash(), check_auth_pending_method(), check_file_access_chroot(), check_for_client_reason(), check_incoming_control_channel(), check_stale_routes(), check_subnet_conflict(), close_tun(), crypto_pem_encode_certificate(), 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_dns_domain_service(), do_dns_service(), do_ifconfig_ipv4(), do_ifconfig_ipv6(), do_ifconfig_setenv(), do_open_tun(), do_pre_decrypt_check(), do_route_service(), do_set_mtu_service(), do_wins_service(), drop_if_recursive_routing(), establish_http_proxy_passthru(), export_user_keying_material(), fork_dhcp_action(), fork_register_dns_action(), frame_print(), generate_auth_token(), generate_key_random(), generate_prefix(), get_adapter_index_method_2(), get_bypass_addresses(), get_default_gateway(), get_default_gateway_ipv6(), get_default_gateway_row(), get_p2p_ncp_cipher(), get_user_pass_cr(), handle_data_channel_packet(), helper_client_server(), ifconfig_pool_init(), ifconfig_pool_list(), ifconfig_pool_read(), ifconfig_pool_verify_range(), ifconfig_sanity_check(), incoming_push_message(), inherit_context_child(), init_key_ctx(), init_route_ipv6_list(), init_route_list(), init_ssl(), init_static(), ip_addr_string_to_array(), key_method_2_read(), key_print(), key_source_print(), key_state_gen_auth_control_files(), 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(), management_callback_send_cc_message(), management_echo(), management_hold(), management_learn_addr(), management_notify_client_cr_response(), management_query_multiline(), management_query_user_pass(), management_set_state(), mroute_extract_addr_ip(), mroute_helper_regenerate(), multi_add_iroutes(), multi_client_connect_call_script(), multi_client_connect_late_setup(), multi_client_connect_setenv(), multi_client_connect_source_ccd(), multi_client_set_protocol_options(), 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_reap_range(), multi_select_virtual_addr(), multi_tcp_post(), ncp_get_best_cipher(), netsh_ifconfig(), netsh_ifconfig_options(), netsh_set_dns6_servers(), open_tun(), openvpn_execve(), 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(), p2p_mode_ncp(), packet_id_persist_load(), packet_id_persist_save(), parse_auth_failed_temp(), parse_hash_fingerprint_multiline(), 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(), pre_connect_restore(), print_client_nat_list(), print_default_gateway(), print_key_id_not_found_reason(), print_pkt(), print_route(), print_status(), process_incoming_link_part1(), process_incoming_push_request(), process_incoming_tun(), process_outgoing_link(), push_peer_info(), read_control_auth(), read_key_file(), read_pem_key_file(), recv_socks_reply(), redirect_stdout_stderr(), register_dns_service(), reliable_ack_read(), reliable_can_get(), reliable_can_send(), reliable_get_buf_output_sequenced(), reliable_get_num_output_sequenced_available(), reliable_not_replay(), reliable_send_timeout(), reliable_wont_break_sequentiality(), remove_iroutes_from_push_route_list(), resolve_bind_local(), resolve_remote(), route_ipv6_ipapi(), route_quota_exceeded(), run_up_down(), send_auth_failed(), send_auth_pending_messages(), send_control_channel_string_dowork(), send_msg_iservice(), send_push_reply(), send_push_reply_auth_token(), server_pushed_info(), service_enable_dhcp(), service_register_ring_buffers(), session_move_pre_start(), setenv_dns_options(), setenv_int_i(), setenv_route(), setenv_route_addr(), setenv_route_ipv6(), setenv_str_ex(), setenv_str_i(), show_adapters(), show_dco_version(), show_dhcp_option_addrs(), show_dns_options(), show_p2mp_parms(), show_routes(), show_settings(), show_tap_win_adapters(), show_windows_version(), socket_bind(), socket_connect(), socket_do_listen(), socket_listen_accept(), socket_recv_queue(), socket_send_queue(), ssl_tls1_PRF(), tap_allow_nonadmin_access(), tcp_connection_established(), test_buffer_format_hex_ex(), test_buffer_free_gc_one(), test_buffer_free_gc_two(), test_buffer_gc_realloc(), test_buffer_printf_catrunc(), test_check_ncp_ciphers_list(), test_cipher_names(), test_compat_lzo_string(), test_crypto(), test_extract_client_ciphers(), test_local_addr(), test_mssfix_mtu_calculation(), test_ncp_best(), test_occ_mtu_calculation(), test_poor_man(), test_routes(), test_tls_crypt_secure_reneg_key(), test_tls_crypt_v2_setup(), tls_authentication_status(), tls_crypt_v2_unwrap_client_key(), tls_crypt_v2_verify_metadata(), tls_crypt_v2_write_client_key_file(), tls_ctx_set_tls_groups(), tls_multi_process(), tls_pre_decrypt(), tls_pre_decrypt_lite(), tls_pre_encrypt(), tls_session_init(), tls_update_remote_addr(), trigger_ping_timeout_signal(), tun_read_queue(), tun_write_queue(), tuntap_dhcp_mask(), tuntap_set_ip_addr(), tuntap_set_ptp(), undo_ifconfig_ipv4(), undo_ifconfig_ipv6(), 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_crresponse_script(), verify_final_auth_checks(), verify_user_pass_script(), virtual_output_callback_func(), warn_on_use_of_common_subnets(), win32_signal_open(), win_block_dns_service(), window_title_generate(), windows_route_find_if_index(), windows_set_mtu(), write_key_file(), write_outgoing_tls_ciphertext(), write_pem_key_file(), x509_setenv_track(), and x_check_status().

◆ gc_realloc()

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

Note
only use this function on pointers returned by gc_malloc or re_alloc with the same gc_arena
Parameters
ptrPointer of the previously allocated memory
sizeNew size
agc_arena to use
Returns
new pointer

Definition at line 414 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_remote_entry(), and test_buffer_gc_realloc().

◆ gc_reset()

static void gc_reset ( struct gc_arena a)
inlinestatic

Definition at line 1052 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 504 of file buffer.c.

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

Referenced by add_option().

◆ has_digit()

static bool has_digit ( const char *  src)
inlinestatic

Definition at line 372 of file buffer.h.

Referenced by tun_name_is_fixed().

◆ np()

const char* np ( const char *  str)

Definition at line 904 of file buffer.c.

◆ openvpn_snprintf()

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

◆ print_argv()

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

Definition at line 761 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 667 of file buffer.c.

References buffer::len.

Referenced by chomp().

◆ 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 414 of file buffer.h.

Referenced by buf_clear(), crypto_read_openvpn_key(), export_user_keying_material(), generate_key_expansion(), generate_key_expansion_openvpn_prf(), key_method_2_read(), key_method_2_write(), key_state_export_keying_material(), key_state_free(), management_query_user_pass(), move_session(), purge_user_pass(), read_config_file(), read_config_string(), read_inline_file(), remove_env_item(), socks_username_password_auth(), ssl_tls1_PRF(), string_clear(), tls_crypt_v2_extract_client_key(), tls_crypt_v2_init_server_key(), tls_crypt_v2_unwrap_client_key(), tls_crypt_v2_write_client_key_file(), tls_multi_free(), tls_session_free(), tls_session_generate_data_channel_keys(), tls_session_generate_dynamic_tls_crypt_key(), tls_wrap_free(), wipe_auth_token(), write_key_file(), and write_pem_key_file().

◆ skip_leading_whitespace()

const char* skip_leading_whitespace ( const char *  str)

Definition at line 623 of file buffer.c.

Referenced by make_inline_array().

◆ 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 796 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 1066 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 
)

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.

Parameters
strThe string to be modified.
inclusiveThe character classes not to be replaced.
exclusiveCharacter classes to be replaced even if they are also in inclusive.
replaceThe character to replace the specified character classes with.
Returns
True if the string was not modified, false otherwise.

Definition at line 1085 of file buffer.c.

References ASSERT, and char_inc_exc().

Referenced by check_incoming_control_channel(), do_setenv_x509(), get_user_pass_cr(), string_mod_const(), string_mod_remap_name(), test_character_class(), verify_user_pass(), wide_cmd_line(), and x509_setenv().

◆ 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 
)

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.

Parameters
strThe input string to be modified.
inclusiveCharacter classes not to be replaced.
exclusiveCharacter classes to be replaced even if they are also in inclusive.
replaceThe character to replace the specified character classes with.
gcThe garbage collector arena to allocate memory from.
Returns
The modified string with characters replaced within the specified range.

Definition at line 1117 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 641 of file buffer.c.

References ASSERT, buffer::capacity, and buffer::len.

Referenced by get_console_input_win32().

◆ string_replace_leading()

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

Definition at line 1136 of file buffer.c.

References ASSERT.

Referenced by verify_cert().

◆ 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 983 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 447 of file buffer.c.

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

Referenced by gc_free().

◆ x_gc_freespecial()

void x_gc_freespecial ( struct gc_arena a)
gc_malloc
void * gc_malloc(size_t size, bool clear, struct gc_arena *a)
Definition: buffer.c:380
array_mult_safe
size_t array_mult_safe(const size_t m1, const size_t m2, const size_t extra)
Definition: buffer.c:41