The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
merged_model.c
Go to the documentation of this file.
1 /* Coverity Scan model
2  *
3  * This is a modeling file for Coverity Scan. Modeling helps to avoid false
4  * positives.
5  *
6  * - A model file can't #include any header files.
7  * - Therefore only some built-in primitives like int, char and void are
8  * available but not wchar_t, NULL etc.
9  * - Modeling doesn't need full structs and typedefs. Rudimentary structs
10  * and similar types are sufficient.
11  * - An uninitialized local pointer is not an error. It signifies that the
12  * variable could be either NULL or have some data.
13  *
14  * Coverity Scan doesn't pick up modifications automatically. The model file
15  * must be uploaded by an admin in the analysis settings of
16  * https://scan.coverity.com/projects/freeradius-freeradius-server?tab=analysis_settings
17  */
18 
19 typedef unsigned char bool;
20 
21 typedef unsigned int mode_t;
22 typedef long long int off_t;
23 
24 typedef long int ssize_t;
25 typedef unsigned long int size_t;
26 
27 typedef union {
29 
30 typedef unsigned char uint8_t;
31 typedef unsigned short uint16_t;
32 #define UINT8_MAX 255
33 typedef unsigned int uint32_t;
34 
36 
37 typedef struct {
38  char *p;
39 } fr_sbuff_t;
40 
41 typedef struct {
43 } fr_dbuff_t;
44 
45 typedef enum {
46  FR_SBUFF_PARSE_OK = 0, //!< No error.
47  FR_SBUFF_PARSE_ERROR_NOT_FOUND = -1, //!< String does not contain a token
48  ///< matching the output type.
49  FR_SBUFF_PARSE_ERROR_TRAILING = -2, //!< Trailing characters found.
50  FR_SBUFF_PARSE_ERROR_FORMAT = -3, //!< Format of data was invalid.
51  FR_SBUFF_PARSE_ERROR_OUT_OF_SPACE = -4, //!< No space available in output buffer.
52  FR_SBUFF_PARSE_ERROR_NUM_OVERFLOW = -5, //!< Integer type would overflow.
53  FR_SBUFF_PARSE_ERROR_NUM_UNDERFLOW = -6 //!< Integer type would underflow.
55 
56 fr_slen_t fr_base16_encode_nstd(fr_sbuff_t *out, fr_dbuff_t *in, char const alphabet[static UINT8_MAX + 1])
57 {
58  fr_slen_t result;
59 
60  if (result >= 0) __coverity_write_buffer_bytes__(out->p, result);
61 
62  return result;
63 }
64 
66  bool no_trailing, uint8_t const alphabet[static UINT8_MAX + 1])
67 {
68  fr_slen_t result;
69 
70  if (result >= 0) __coverity_write_buffer_bytes__(out->p, result + 1);
71 
72  return result;
73 }
74 
75 /*
76  * Here we can use __coverity_writeall__(), which tells coverity "however big the thing
77  * pointed at is, consider it all written."
78  */
79 
80 typedef enum {
81  FR_TYPE_NULL = 0, //!< Invalid (uninitialised) attribute type.
82 
83  FR_TYPE_STRING, //!< String of printable characters.
84  FR_TYPE_OCTETS, //!< Raw octets.
85 
86  FR_TYPE_IPV4_ADDR, //!< 32 Bit IPv4 Address.
87  FR_TYPE_IPV4_PREFIX, //!< IPv4 Prefix.
88  FR_TYPE_IPV6_ADDR, //!< 128 Bit IPv6 Address.
89  FR_TYPE_IPV6_PREFIX, //!< IPv6 Prefix.
90  FR_TYPE_IFID, //!< Interface ID.
91  FR_TYPE_COMBO_IP_ADDR, //!< IPv4 or IPv6 address depending on length.
92  FR_TYPE_COMBO_IP_PREFIX, //!< IPv4 or IPv6 address prefix depending on length.
93  FR_TYPE_ETHERNET, //!< 48 Bit Mac-Address.
94 
95  FR_TYPE_BOOL, //!< A truth value.
96 
97  FR_TYPE_UINT8, //!< 8 Bit unsigned integer.
98  FR_TYPE_UINT16, //!< 16 Bit unsigned integer.
99  FR_TYPE_UINT32, //!< 32 Bit unsigned integer.
100  FR_TYPE_UINT64, //!< 64 Bit unsigned integer.
101 
102 
103  FR_TYPE_INT8, //!< 8 Bit signed integer.
104  FR_TYPE_INT16, //!< 16 Bit signed integer.
105  FR_TYPE_INT32, //!< 32 Bit signed integer.
106  FR_TYPE_INT64, //!< 64 Bit signed integer.
107 
108  FR_TYPE_FLOAT32, //!< Single precision floating point.
109  FR_TYPE_FLOAT64, //!< Double precision floating point.
110 
111  FR_TYPE_DATE, //!< Unix time stamp, always has value >2^31
112 
113  FR_TYPE_TIME_DELTA, //!< A period of time measured in nanoseconds.
114 
115  FR_TYPE_SIZE, //!< Unsigned integer capable of representing any memory
116  //!< address on the local system.
117 
118  FR_TYPE_TLV, //!< Contains nested attributes.
119  FR_TYPE_STRUCT, //!< like TLV, but without T or L, and fixed-width children
120 
121  FR_TYPE_VSA, //!< Vendor-Specific, for RADIUS attribute 26.
122  FR_TYPE_VENDOR, //!< Attribute that represents a vendor in the attribute tree.
123 
124  FR_TYPE_GROUP, //!< A grouping of other attributes
125  FR_TYPE_VALUE_BOX, //!< A boxed value.
126 
127  FR_TYPE_VOID, //!< User data. Should be a talloced chunk
128  ///< assigned to the ptr value of the union.
129 
130  FR_TYPE_MAX //!< Number of defined data types.
132 
133 typedef struct {
135 
136 typedef struct {
138 
139 typedef struct {
141 
143 {
144  ssize_t result;
145 
146  if (result >= 0) __coverity_write_buffer_bytes__(out->p, result);
147 
148  return result;
149 }
150 
152  bool const allowed[static UINT8_MAX + 1])
153 {
154  size_t result;
155 
156  __coverity_write_buffer_bytes__(out->p, result + 1);
157 
158  return result;
159 }
160 
161 typedef struct {
163 typedef struct {
165 
167  fr_sbuff_term_t const *tt,
168  fr_sbuff_unescape_rules_t const *u_rules)
169 {
170  size_t result;
171 
172  __coverity_write_buffer_bytes__(out->p, result + 1);
173 
174  return result;
175 }
176 
178  fr_sbuff_term_t const *tt,
179  fr_sbuff_unescape_rules_t const *u_rules)
180 {
181  size_t result;
182 
183  __coverity_write_buffer_bytes__(out->p, result + 1);
184 
185  return result;
186 }
187 
189  fr_dict_attr_t const *ancestor, fr_dict_attr_t const *da, bool numeric)
190 {
191  ssize_t result;
192 
193  if (result > 0) __coverity_write_buffer_bytes__(out->p, result);
194 
195  return result;
196 }
197 
198 typedef struct {
199 } fr_dict_t;
200 
202 {
203  ssize_t result;
204 
205  if (result > 0) __coverity_write_buffer_bytes__(out->p, result);
206 
207  return result;
208 }
209 
210 typedef struct {
211 } request_t;
212 
213 typedef size_t (*xlat_escape_legacy_t)(request_t *request, char *out, size_t outlen, char const *in, void *arg);
214 
215 ssize_t xlat_eval(char *out, size_t outlen, request_t *request,
216  char const *fmt, xlat_escape_legacy_t escape, void const *escape_ctx)
217 {
218  ssize_t result;
219 
220  if (result > 0) __coverity_write_buffer_bytes__(out, result + 1);
221 
222  return result;
223 }
224 
225 typedef struct {
226 } tmpl_t;
227 
228 typedef enum {
229  TMPL_ATTR_REF_PREFIX_YES = 0, //!< Attribute refs must have '&' prefix.
230  TMPL_ATTR_REF_PREFIX_NO, //!< Attribute refs have no '&' prefix.
231  TMPL_ATTR_REF_PREFIX_AUTO //!< Attribute refs may have a '&' prefix.
233 
234 typedef struct {
236 
239 {
240  fr_slen_t result;
241 
242  if (result >= 0) __coverity_write_buffer_bytes__(out->p, result + 1);
243 
244  return result;
245 }
246 
247 #ifndef MD5_DIGEST_LENGTH
248 # define MD5_DIGEST_LENGTH 16
249 #endif
250 
251 void fr_md5_calc(uint8_t out[static MD5_DIGEST_LENGTH], uint8_t const *in, size_t inlen)
252 {
253  __coverity_write_buffer_bytes__(out, MD5_DIGEST_LENGTH);
254 }
255 
256 typedef struct {
257 } decode_fail_t;
258 
259 bool fr_radius_ok(uint8_t const *packet, size_t *packet_len_p,
260  uint32_t max_attributes, bool require_message_authenticator, decode_fail_t *reason)
261 {
262  bool result;
263 
264  if (result) {
265  __coverity_mark_pointee_as_sanitized__(&packet, TAINTED_SCALAR_GENERIC);
266  __coverity_mark_pointee_as_sanitized__(packet, TAINTED_SCALAR_GENERIC);
267  __coverity_mark_pointee_as_sanitized__(packet_len_p, TAINTED_SCALAR_GENERIC);
268  }
269  return result;
270 }
271 
272 typedef struct {
273 } fr_ipaddr_t;
274 
275 int fr_inet_pton4(fr_ipaddr_t *out, char const *value, ssize_t inlen, bool resolve, bool fallback, bool mask_bits)
276 {
277  int result;
278 
279  __coverity_writeall__(out);
280  return result;
281 }
static int const char * fmt
Definition: acutest.h:573
static fr_dict_t * dict
Definition: fuzzer.c:46
struct fr_dbuff_s fr_dbuff_t
A dbuff.
Definition: dbuff.h:65
static fr_slen_t err
Definition: dict.h:821
struct value_box_s fr_value_box_t
Definition: dict.h:49
struct fr_dict_s fr_dict_t
Definition: dict.h:47
static fr_slen_t in
Definition: dict.h:821
struct dict_attr_s fr_dict_attr_t
Definition: dict.h:46
Values of the encryption flags.
Definition: merged_model.c:139
Test enumeration values.
Definition: dict_test.h:92
IPv4/6 prefix.
Definition: merged_model.c:272
tmpl_attr_prefix_t
Definition: merged_model.c:228
@ TMPL_ATTR_REF_PREFIX_NO
Attribute refs have no '&' prefix.
Definition: merged_model.c:230
@ TMPL_ATTR_REF_PREFIX_AUTO
Attribute refs may have a '&' prefix.
Definition: merged_model.c:231
@ TMPL_ATTR_REF_PREFIX_YES
Attribute refs must have '&' prefix.
Definition: merged_model.c:229
#define MD5_DIGEST_LENGTH
Definition: merged_model.c:248
bool fr_radius_ok(uint8_t const *packet, size_t *packet_len_p, uint32_t max_attributes, bool require_message_authenticator, decode_fail_t *reason)
Definition: merged_model.c:259
unsigned short uint16_t
Definition: merged_model.c:31
fr_slen_t tmpl_print(fr_sbuff_t *out, tmpl_t const *vpt, tmpl_attr_prefix_t ar_prefix, fr_sbuff_escape_rules_t const *e_rules)
Definition: merged_model.c:237
size_t(* xlat_escape_legacy_t)(request_t *request, char *out, size_t outlen, char const *in, void *arg)
Definition: merged_model.c:213
size_t fr_sbuff_out_unescape_until(fr_sbuff_t *out, fr_sbuff_t *in, size_t len, fr_sbuff_term_t const *tt, fr_sbuff_unescape_rules_t const *u_rules)
Definition: merged_model.c:177
fr_type_t
Definition: merged_model.c:80
@ FR_TYPE_TIME_DELTA
A period of time measured in nanoseconds.
Definition: merged_model.c:113
@ FR_TYPE_FLOAT32
Single precision floating point.
Definition: merged_model.c:108
@ FR_TYPE_IPV4_ADDR
32 Bit IPv4 Address.
Definition: merged_model.c:86
@ FR_TYPE_INT8
8 Bit signed integer.
Definition: merged_model.c:103
@ FR_TYPE_TLV
Contains nested attributes.
Definition: merged_model.c:118
@ FR_TYPE_ETHERNET
48 Bit Mac-Address.
Definition: merged_model.c:93
@ FR_TYPE_IPV6_PREFIX
IPv6 Prefix.
Definition: merged_model.c:89
@ FR_TYPE_STRING
String of printable characters.
Definition: merged_model.c:83
@ FR_TYPE_MAX
Number of defined data types.
Definition: merged_model.c:130
@ FR_TYPE_NULL
Invalid (uninitialised) attribute type.
Definition: merged_model.c:81
@ FR_TYPE_UINT16
16 Bit unsigned integer.
Definition: merged_model.c:98
@ FR_TYPE_INT64
64 Bit signed integer.
Definition: merged_model.c:106
@ FR_TYPE_INT16
16 Bit signed integer.
Definition: merged_model.c:104
@ FR_TYPE_DATE
Unix time stamp, always has value >2^31.
Definition: merged_model.c:111
@ FR_TYPE_COMBO_IP_PREFIX
IPv4 or IPv6 address prefix depending on length.
Definition: merged_model.c:92
@ FR_TYPE_VALUE_BOX
A boxed value.
Definition: merged_model.c:125
@ FR_TYPE_UINT8
8 Bit unsigned integer.
Definition: merged_model.c:97
@ FR_TYPE_UINT32
32 Bit unsigned integer.
Definition: merged_model.c:99
@ FR_TYPE_STRUCT
like TLV, but without T or L, and fixed-width children
Definition: merged_model.c:119
@ FR_TYPE_INT32
32 Bit signed integer.
Definition: merged_model.c:105
@ FR_TYPE_VENDOR
Attribute that represents a vendor in the attribute tree.
Definition: merged_model.c:122
@ FR_TYPE_UINT64
64 Bit unsigned integer.
Definition: merged_model.c:100
@ FR_TYPE_IPV6_ADDR
128 Bit IPv6 Address.
Definition: merged_model.c:88
@ FR_TYPE_IPV4_PREFIX
IPv4 Prefix.
Definition: merged_model.c:87
@ FR_TYPE_VOID
User data.
Definition: merged_model.c:127
@ FR_TYPE_BOOL
A truth value.
Definition: merged_model.c:95
@ FR_TYPE_SIZE
Unsigned integer capable of representing any memory address on the local system.
Definition: merged_model.c:115
@ FR_TYPE_VSA
Vendor-Specific, for RADIUS attribute 26.
Definition: merged_model.c:121
@ FR_TYPE_COMBO_IP_ADDR
IPv4 or IPv6 address depending on length.
Definition: merged_model.c:91
@ FR_TYPE_IFID
Interface ID.
Definition: merged_model.c:90
@ FR_TYPE_OCTETS
Raw octets.
Definition: merged_model.c:84
@ FR_TYPE_GROUP
A grouping of other attributes.
Definition: merged_model.c:124
@ FR_TYPE_FLOAT64
Double precision floating point.
Definition: merged_model.c:109
uint8_t * p
Definition: merged_model.c:42
unsigned int uint32_t
Definition: merged_model.c:33
ssize_t fr_dict_attr_flags_print(fr_sbuff_t *out, fr_dict_t const *dict, fr_type_t type, fr_dict_attr_flags_t const *flags)
Definition: merged_model.c:201
int fr_inet_pton4(fr_ipaddr_t *out, char const *value, ssize_t inlen, bool resolve, bool fallback, bool mask_bits)
Definition: merged_model.c:275
fr_slen_t fr_base16_encode_nstd(fr_sbuff_t *out, fr_dbuff_t *in, char const alphabet[static UINT8_MAX+1])
Definition: merged_model.c:56
long int ssize_t
Definition: merged_model.c:24
ssize_t fr_sbuff_out_bstrncpy_exact(fr_sbuff_t *out, fr_sbuff_t *in, size_t len)
Definition: merged_model.c:142
ssize_t fr_dict_attr_oid_print(fr_sbuff_t *out, fr_dict_attr_t const *ancestor, fr_dict_attr_t const *da, bool numeric)
Definition: merged_model.c:188
size_t fr_sbuff_out_bstrncpy_until(fr_sbuff_t *out, fr_sbuff_t *in, size_t len, fr_sbuff_term_t const *tt, fr_sbuff_unescape_rules_t const *u_rules)
Definition: merged_model.c:166
unsigned char bool
Definition: merged_model.c:19
ssize_t xlat_eval(char *out, size_t outlen, request_t *request, char const *fmt, xlat_escape_legacy_t escape, void const *escape_ctx)
Definition: merged_model.c:215
char * p
Definition: merged_model.c:38
void fr_md5_calc(uint8_t out[static MD5_DIGEST_LENGTH], uint8_t const *in, size_t inlen)
Perform a single digest operation on a single input buffer.
Definition: merged_model.c:251
unsigned char uint8_t
Definition: merged_model.c:30
fr_slen_t fr_base16_decode_nstd(fr_sbuff_parse_error_t *err, fr_dbuff_t *out, fr_sbuff_t *in, bool no_trailing, uint8_t const alphabet[static UINT8_MAX+1])
Definition: merged_model.c:65
unsigned int mode_t
Definition: merged_model.c:21
ssize_t fr_slen_t
Definition: merged_model.c:35
long long int off_t
Definition: merged_model.c:22
unsigned long int size_t
Definition: merged_model.c:25
#define UINT8_MAX
Definition: merged_model.c:32
fr_sbuff_parse_error_t
Definition: merged_model.c:45
@ FR_SBUFF_PARSE_ERROR_NUM_OVERFLOW
Integer type would overflow.
Definition: merged_model.c:52
@ FR_SBUFF_PARSE_ERROR_NUM_UNDERFLOW
Integer type would underflow.
Definition: merged_model.c:53
@ FR_SBUFF_PARSE_ERROR_NOT_FOUND
String does not contain a token matching the output type.
Definition: merged_model.c:47
@ FR_SBUFF_PARSE_ERROR_FORMAT
Format of data was invalid.
Definition: merged_model.c:50
@ FR_SBUFF_PARSE_OK
No error.
Definition: merged_model.c:46
@ FR_SBUFF_PARSE_ERROR_OUT_OF_SPACE
No space available in output buffer.
Definition: merged_model.c:51
@ FR_SBUFF_PARSE_ERROR_TRAILING
Trailing characters found.
Definition: merged_model.c:49
size_t fr_sbuff_out_bstrncpy_allowed(fr_sbuff_t *out, fr_sbuff_t *in, size_t len, bool const allowed[static UINT8_MAX+1])
Definition: merged_model.c:151
struct request_s request_t
Definition: radclient-ng.c:53
struct fr_sbuff_s fr_sbuff_t
Definition: sbuff.h:52
Set of terminal elements.
Definition: merged_model.c:161
Set of parsing rules for *unescape_until functions.
Definition: merged_model.c:163
static fr_slen_t ar_prefix
Definition: tmpl.h:1279
static fr_slen_t vpt
Definition: tmpl.h:1272
struct tmpl_s tmpl_t
Definition: tmpl.h:241
fr_aka_sim_id_type_t type
decode_fail_t
Failure reasons.
Definition: test_point.h:23
static size_t char fr_sbuff_t size_t inlen
Definition: value.h:997
static size_t char ** out
Definition: value.h:997