The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
strerror.h File Reference

Support functions to allow libraries to provide errors to their callers. More...

#include <freeradius-devel/build.h>
#include <freeradius-devel/missing.h>
#include <string.h>
#include <stdarg.h>
+ Include dependency graph for strerror.h:

Go to the source code of this file.

Add an error string to the thread local error stack

Note
printf functions should not be used in decoder libraries as an attacker may be able to exploit them to consume excessive amounts of CPU time. Use fr_strerror_const_* functions instead.
static void _fr_strerror_printf (char const *file, int line, char const *fmt,...)
 
static void _fr_strerror_printf_push (char const *file, int line, char const *fmt,...)
 
static void _fr_strerror_printf_push_head (char const *file, int line, char const *fmt,...)
 
void _fr_strerror_vprintf (char const *file, int line, char const *fmt, va_list ap)
 Log to thread local error buffer. More...
 
void _fr_strerror_vprintf_push (char const *file, int line, char const *fmt, va_list ap)
 Add a message to an existing stack of messages at the tail. More...
 
void _fr_strerror_vprintf_push_head (char const *file, int line, char const *fmt, va_list ap)
 Add a message to an existing stack of messages at the head. More...
 
#define fr_strerror_printf(_fmt, ...)    _fr_strerror_printf(__FILE__, __LINE__, _fmt, ##__VA_ARGS__)
 Log to thread local error buffer. More...
 
#define fr_strerror_printf_push(_fmt, ...)    _fr_strerror_printf_push(__FILE__, __LINE__, _fmt, ##__VA_ARGS__)
 Add a message to an existing stack of messages at the tail. More...
 
#define fr_strerror_printf_push_head(_fmt, ...)    _fr_strerror_printf_push_head(__FILE__, __LINE__, _fmt, ##__VA_ARGS__)
 Add a message to an existing stack of messages at the head. More...
 
#define fr_strerror_vprintf(_fmt, _ap)   _fr_strerror_vprintf(__FILE__, __LINE__, _fmt, _ap)
 
#define fr_strerror_vprintf_push(_fmt, _ap)   _fr_strerror_vprintf_push(__FILE__, __LINE, _fmt, _ap)
 
#define fr_strerror_vprintf_push_head(_fmt, _ap)   _fr_strerror_vprintf_push_head(__FILE__, __LINE__, _fmt, _ap)
 

Add an error string with marker to the thread local error stack

Note
printf functions should not be used in decoder libraries as an attacker may be able to exploit them to consume excessive amounts of CPU time. Use fr_strerror_const_* functions instead.
static void _fr_strerror_marker_printf (char const *file, int line, char const *subject, size_t offset, char const *fmt,...)
 
static void _fr_strerror_marker_printf_push (char const *file, int line, char const *subject, size_t offset, char const *fmt,...)
 
static void _fr_strerror_marker_printf_push_head (char const *file, int line, char const *subject, size_t offset, char const *fmt,...)
 
void _fr_strerror_marker_vprintf (char const *file, int line, char const *subject, size_t offset, char const *fmt, va_list ap)
 Add an error marker to an existing stack of messages. More...
 
void _fr_strerror_marker_vprintf_push (char const *file, int line, char const *subject, size_t offset, char const *fmt, va_list ap)
 Add an error marker to an existing stack of messages at the tail. More...
 
void _fr_strerror_marker_vprintf_push_head (char const *file, int line, char const *subject, size_t offset, char const *fmt, va_list ap)
 Add an error marker to an existing stack of messages at the head. More...
 
#define fr_strerror_marker_printf(_subject, _offset, _fmt, ...)    _fr_strerror_marker_printf(__FILE__, __LINE__, _subject, _offset, _fmt, ##__VA_ARGS__)
 Add an error marker to an existing stack of messages. More...
 
#define fr_strerror_marker_printf_push(_subject, _offset, _fmt, ...)    _fr_strerror_marker_printf_push(__FILE__, __LINE__, _subject, _offset, _fmt, ##__VA_ARGS__)
 Add an error marker to an existing stack of messages at the tail. More...
 
#define fr_strerror_marker_printf_push_head(_subject, _offset, _fmt, ...)    _fr_strerror_marker_printf_push_head(__FILE__, __LINE__, _subject, _offset, _fmt, ##__VA_ARGS__)
 Add an error marker to an existing stack of messages at the head. More...
 
#define fr_strerror_marker_vprintf(_subject, _offset, _fmt, _ap)    _fr_strerror_marker_vprintf(__FILE__, __LINE__, _subject, _offset, _fmt, _ap)
 
#define fr_strerror_marker_vprintf_push(_subject, _offset, _fmt, _ap)    _fr_strerror_marker_vprintf_push(__FILE__, __LINE__, _subject, _offset, _fmt, _ap)
 
#define fr_strerror_marker_vprintf_push_head(_subject, _offset, _fmt, _ap)    _fr_strerror_marker_vprintf_push_head(__FILE__, __LINE__, _subject, _offset, _fmt, _ap)
 

Add a const error string to the thread local error stack

Note
This ~30x the speed of the printf variants, and should be used wherever possible
void _fr_strerror_const (char const *file, int line, char const *msg)
 Log to thread local error buffer. More...
 
void _fr_strerror_const_push (char const *file, int line, char const *msg)
 Add a message to an existing stack of messages at the tail. More...
 
void _fr_strerror_const_push_head (char const *file, int line, char const *msg)
 Add a message to an existing stack of messages at the head. More...
 
#define fr_strerror_const(_msg)   _fr_strerror_const(__FILE__, __LINE__, _msg)
 
#define fr_strerror_const_push(_msg)   _fr_strerror_const_push(__FILE__, __LINE__, _msg)
 
#define fr_strerror_const_push_head(_msg)   _fr_strerror_const_push_head(__FILE__, __LINE__, _msg)
 

Retrieve errors from the thread local error stack

void fr_perror (char const *,...))
 Print the current error to stderr with a prefix. More...
 
char const * fr_perror_to_str (char const *line_sep, char const *fmt,...))
 Print the stack of string buffers to a thread local buffer. More...
 
char const * fr_strerror (void)
 Get the last library error. More...
 
void fr_strerror_clear (void)
 Clears all pending messages from the talloc pools. More...
 
char const * fr_strerror_marker (char const **subject, size_t *offset)
 Get the last library error marker. More...
 
char const * fr_strerror_marker_peek (char const **subject, size_t *offset)
 Get the last library error marker. More...
 
char const * fr_strerror_marker_pop (char const **subject, size_t *offset)
 Pop the last library error with marker information. More...
 
char const * fr_strerror_peek (void)
 Get the last library error. More...
 
char const * fr_strerror_pop (void)
 Pop the last library error. More...
 

Detailed Description

Support functions to allow libraries to provide errors to their callers.

Definition in file strerror.h.

Macro Definition Documentation

◆ fr_strerror_const

#define fr_strerror_const (   _msg)    _fr_strerror_const(__FILE__, __LINE__, _msg)

Definition at line 223 of file strerror.h.

◆ fr_strerror_const_push

#define fr_strerror_const_push (   _msg)    _fr_strerror_const_push(__FILE__, __LINE__, _msg)

Definition at line 227 of file strerror.h.

◆ fr_strerror_const_push_head

#define fr_strerror_const_push_head (   _msg)    _fr_strerror_const_push_head(__FILE__, __LINE__, _msg)

Definition at line 231 of file strerror.h.

◆ fr_strerror_marker_printf

#define fr_strerror_marker_printf (   _subject,
  _offset,
  _fmt,
  ... 
)     _fr_strerror_marker_printf(__FILE__, __LINE__, _subject, _offset, _fmt, ##__VA_ARGS__)

Add an error marker to an existing stack of messages.

Parameters
[in]_subjectto mark up.
[in]_offsetPositive offset to show where the error should be positioned.
[in]_fmtError string.
[in]...Arguments for the error string.

Definition at line 154 of file strerror.h.

◆ fr_strerror_marker_printf_push

#define fr_strerror_marker_printf_push (   _subject,
  _offset,
  _fmt,
  ... 
)     _fr_strerror_marker_printf_push(__FILE__, __LINE__, _subject, _offset, _fmt, ##__VA_ARGS__)

Add an error marker to an existing stack of messages at the tail.

Parameters
[in]_subjectto mark up.
[in]_offsetPositive offset to show where the error should be positioned.
[in]_fmtError string.
[in]...Arguments for the error string.

Definition at line 178 of file strerror.h.

◆ fr_strerror_marker_printf_push_head

#define fr_strerror_marker_printf_push_head (   _subject,
  _offset,
  _fmt,
  ... 
)     _fr_strerror_marker_printf_push_head(__FILE__, __LINE__, _subject, _offset, _fmt, ##__VA_ARGS__)

Add an error marker to an existing stack of messages at the head.

Parameters
[in]_subjectto mark up.
[in]_offsetPositive offset to show where the error should be positioned.
[in]_fmtError string.
[in]...Arguments for the error string.

Definition at line 202 of file strerror.h.

◆ fr_strerror_marker_vprintf

#define fr_strerror_marker_vprintf (   _subject,
  _offset,
  _fmt,
  _ap 
)     _fr_strerror_marker_vprintf(__FILE__, __LINE__, _subject, _offset, _fmt, _ap)

Definition at line 126 of file strerror.h.

◆ fr_strerror_marker_vprintf_push

#define fr_strerror_marker_vprintf_push (   _subject,
  _offset,
  _fmt,
  _ap 
)     _fr_strerror_marker_vprintf_push(__FILE__, __LINE__, _subject, _offset, _fmt, _ap)

Definition at line 132 of file strerror.h.

◆ fr_strerror_marker_vprintf_push_head

#define fr_strerror_marker_vprintf_push_head (   _subject,
  _offset,
  _fmt,
  _ap 
)     _fr_strerror_marker_vprintf_push_head(__FILE__, __LINE__, _subject, _offset, _fmt, _ap)

Definition at line 138 of file strerror.h.

◆ fr_strerror_printf

#define fr_strerror_printf (   _fmt,
  ... 
)     _fr_strerror_printf(__FILE__, __LINE__, _fmt, ##__VA_ARGS__)

Log to thread local error buffer.

Parameters
[in]_fmtprintf style format string. If NULL clears any existing messages.
[in]...Arguments for the format string.

Definition at line 64 of file strerror.h.

◆ fr_strerror_printf_push

#define fr_strerror_printf_push (   _fmt,
  ... 
)     _fr_strerror_printf_push(__FILE__, __LINE__, _fmt, ##__VA_ARGS__)

Add a message to an existing stack of messages at the tail.

Parameters
[in]_fmtprintf style format string.
[in]...Arguments for the format string.

Definition at line 84 of file strerror.h.

◆ fr_strerror_printf_push_head

#define fr_strerror_printf_push_head (   _fmt,
  ... 
)     _fr_strerror_printf_push_head(__FILE__, __LINE__, _fmt, ##__VA_ARGS__)

Add a message to an existing stack of messages at the head.

Parameters
[in]_fmtprintf style format string.
[in]...Arguments for the format string.

Definition at line 104 of file strerror.h.

◆ fr_strerror_vprintf

#define fr_strerror_vprintf (   _fmt,
  _ap 
)    _fr_strerror_vprintf(__FILE__, __LINE__, _fmt, _ap)

Definition at line 44 of file strerror.h.

◆ fr_strerror_vprintf_push

#define fr_strerror_vprintf_push (   _fmt,
  _ap 
)    _fr_strerror_vprintf_push(__FILE__, __LINE, _fmt, _ap)

Definition at line 48 of file strerror.h.

◆ fr_strerror_vprintf_push_head

#define fr_strerror_vprintf_push_head (   _fmt,
  _ap 
)    _fr_strerror_vprintf_push_head(__FILE__, __LINE__, _fmt, _ap)

Definition at line 52 of file strerror.h.

Function Documentation

◆ _fr_strerror_const()

void _fr_strerror_const ( char const *  file,
int  line,
char const *  msg 
)

Log to thread local error buffer.

Parameters
[in]filethe error occurred in.
[in]linethe error occurred on.
[in]msgTo add to error stack. Must have a lifetime equal to that of the program.

Definition at line 450 of file strerror.c.

+ Here is the call graph for this function:

◆ _fr_strerror_const_push()

void _fr_strerror_const_push ( char const *  file,
int  line,
char const *  msg 
)

Add a message to an existing stack of messages at the tail.

Parameters
[in]filethe error occurred in.
[in]linethe error occurred on.
[in]msgTo add to error stack. Must have a lifetime equal to that of the program.

Definition at line 508 of file strerror.c.

+ Here is the call graph for this function:

◆ _fr_strerror_const_push_head()

void _fr_strerror_const_push_head ( char const *  file,
int  line,
char const *  msg 
)

Add a message to an existing stack of messages at the head.

Parameters
[in]filethe error occurred in.
[in]linethe error occurred on.
[in]msgTo add to error stack. Must have a lifetime equal to that of the program.

Definition at line 531 of file strerror.c.

+ Here is the call graph for this function:

◆ _fr_strerror_marker_printf()

static void _fr_strerror_marker_printf ( char const *  file,
int  line,
char const *  subject,
size_t  offset,
char const *  fmt,
  ... 
)
inlinestatic

Definition at line 158 of file strerror.h.

+ Here is the call graph for this function:

◆ _fr_strerror_marker_printf_push()

static void _fr_strerror_marker_printf_push ( char const *  file,
int  line,
char const *  subject,
size_t  offset,
char const *  fmt,
  ... 
)
inlinestatic

Definition at line 182 of file strerror.h.

+ Here is the call graph for this function:

◆ _fr_strerror_marker_printf_push_head()

static void _fr_strerror_marker_printf_push_head ( char const *  file,
int  line,
char const *  subject,
size_t  offset,
char const *  fmt,
  ... 
)
inlinestatic

Definition at line 206 of file strerror.h.

+ Here is the call graph for this function:

◆ _fr_strerror_marker_vprintf()

void _fr_strerror_marker_vprintf ( char const *  file,
int  line,
char const *  subject,
size_t  offset,
char const *  fmt,
va_list  ap 
)

Add an error marker to an existing stack of messages.

Parameters
[in]filethe error occurred in.
[in]linethe error occurred on.
[in]subjectto mark up.
[in]offsetPositive offset to show where the error should be positioned.
[in]fmtError string.
[in]apArguments for the error string.

Definition at line 320 of file strerror.c.

+ Here is the call graph for this function:

◆ _fr_strerror_marker_vprintf_push()

void _fr_strerror_marker_vprintf_push ( char const *  file,
int  line,
char const *  subject,
size_t  offset,
char const *  fmt,
va_list  ap 
)

Add an error marker to an existing stack of messages at the tail.

Parameters
[in]filethe error occurred in.
[in]linethe error occurred on.
[in]subjectto mark up.
[in]offsetPositive offset to show where the error should be positioned.
[in]fmtError string.
[in]apArguments for the error string.

Definition at line 348 of file strerror.c.

+ Here is the call graph for this function:

◆ _fr_strerror_marker_vprintf_push_head()

void _fr_strerror_marker_vprintf_push_head ( char const *  file,
int  line,
char const *  subject,
size_t  offset,
char const *  fmt,
va_list  ap 
)

Add an error marker to an existing stack of messages at the head.

Parameters
[in]filethe error occurred in.
[in]linethe error occurred on.
[in]subjectto mark up.
[in]offsetPositive offset to show where the error should be positioned.
[in]fmtError string.
[in]apArguments for the error string.

Definition at line 382 of file strerror.c.

+ Here is the call graph for this function:

◆ _fr_strerror_printf()

static void _fr_strerror_printf ( char const *  file,
int  line,
char const *  fmt,
  ... 
)
inlinestatic

Definition at line 68 of file strerror.h.

+ Here is the call graph for this function:

◆ _fr_strerror_printf_push()

static void _fr_strerror_printf_push ( char const *  file,
int  line,
char const *  fmt,
  ... 
)
inlinestatic

Definition at line 88 of file strerror.h.

+ Here is the call graph for this function:

◆ _fr_strerror_printf_push_head()

static void _fr_strerror_printf_push_head ( char const *  file,
int  line,
char const *  fmt,
  ... 
)
inlinestatic

Definition at line 108 of file strerror.h.

+ Here is the call graph for this function:

◆ _fr_strerror_vprintf()

void _fr_strerror_vprintf ( char const *  file,
int  line,
char const *  fmt,
va_list  ap 
)

Log to thread local error buffer.

Parameters
[in]filethe error occurred in.
[in]linethe error occurred on.
[in]fmtprintf style format string. If NULL clears any existing messages.
[in]apArguments for the format string.

Definition at line 245 of file strerror.c.

+ Here is the call graph for this function:

◆ _fr_strerror_vprintf_push()

void _fr_strerror_vprintf_push ( char const *  file,
int  line,
char const *  fmt,
va_list  ap 
)

Add a message to an existing stack of messages at the tail.

Parameters
[in]filethe error occurred in.
[in]linethe error occurred on.
[in]fmtprintf style format string.
[in]apArguments for the format string.

Definition at line 263 of file strerror.c.

+ Here is the call graph for this function:

◆ _fr_strerror_vprintf_push_head()

void _fr_strerror_vprintf_push_head ( char const *  file,
int  line,
char const *  fmt,
va_list  ap 
)

Add a message to an existing stack of messages at the head.

Parameters
[in]filethe error occurred in.
[in]linethe error occurred on.
[in]fmtprintf style format string.
[in]apArguments for the format string.

Definition at line 290 of file strerror.c.

+ Here is the call graph for this function:

◆ fr_perror()

void fr_perror ( char const *  fmt,
  ... 
)

Print the current error to stderr with a prefix.

Used by utility functions lacking their own logging infrastructure

Definition at line 733 of file strerror.c.

+ Here is the call graph for this function:

◆ fr_perror_to_str()

char const* fr_perror_to_str ( char const *  line_sep,
char const *  fmt,
  ... 
)

Print the stack of string buffers to a thread local buffer.

Used by utility functions lacking their own logging infrastructure

Parameters
[in]line_septo insert between the log lines.
[in]fmtto prefix all log messages with.
Returns
  • A thread local string buffer containing the concatenated messages.

Definition at line 779 of file strerror.c.

+ Here is the call graph for this function:

◆ fr_strerror()

char const* fr_strerror ( void  )

Get the last library error.

Will only return the last library error once, after which it will return a zero length string. If there are additional messages on the log stack they will be discarded.

Returns
library error or zero length string.

Definition at line 554 of file strerror.c.

+ Here is the call graph for this function:

◆ fr_strerror_clear()

void fr_strerror_clear ( void  )

Clears all pending messages from the talloc pools.

Definition at line 577 of file strerror.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_strerror_marker()

char const* fr_strerror_marker ( char const **  subject,
size_t offset 
)

Get the last library error marker.

Parameters
[out]subjectThe subject string the error relates to.
[out]offsetWhere to place the marker.
Returns
  • NULL if there are no pending errors.
  • The error message if there was an error.

Definition at line 598 of file strerror.c.

+ Here is the call graph for this function:

◆ fr_strerror_marker_peek()

char const* fr_strerror_marker_peek ( char const **  subject,
size_t offset 
)

Get the last library error marker.

Parameters
[out]subjectThe subject string the error relates to.
[out]offsetWhere to place the marker.
Returns
  • NULL if there are no pending errors.
  • The error message if there was an error.

Definition at line 651 of file strerror.c.

+ Here is the call graph for this function:

◆ fr_strerror_marker_pop()

char const* fr_strerror_marker_pop ( char const **  subject,
size_t offset 
)

Pop the last library error with marker information.

Return the first message added to the error stack using fr_strerror_printf or fr_strerror_printf_push.

Returns
  • A library error.
  • NULL if no errors are pending.

Definition at line 708 of file strerror.c.

+ Here is the call graph for this function:

◆ fr_strerror_peek()

char const* fr_strerror_peek ( void  )

Get the last library error.

Returns
library error or zero length string.

Definition at line 627 of file strerror.c.

+ Here is the call graph for this function:

◆ fr_strerror_pop()

char const* fr_strerror_pop ( void  )

Pop the last library error.

Return the first message added to the error stack using fr_strerror_printf or fr_strerror_printf_push.

Note
Unlink fr_strerror() will return NULL if no messages are pending.
Returns
  • A library error.
  • NULL if no errors are pending.

Definition at line 681 of file strerror.c.

+ Here is the call graph for this function: