The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
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
19typedef unsigned char bool;
20
21typedef long int ssize_t;
22typedef unsigned long int size_t;
23
24typedef unsigned char uint8_t;
25typedef unsigned short uint16_t;
26#define UINT8_MAX 255
27typedef unsigned int uint32_t;
28
30
31/*
32 * The unions match the real structs. FR_SBUFF_IN(), FR_SBUFF_OUT() and
33 * FR_DBUFF_TMP() set the immutable members (buff_i, start_i, end_i and
34 * p_i), so the models below write through p_i, the member the caller's
35 * buffer pointer was stored in.
36 */
37typedef struct {
38 union {
39 char const *buff_i;
40 char *buff;
41 };
42 union {
43 char const *start_i;
44 char *start;
45 };
46 union {
47 char const *end_i;
48 char *end;
49 };
50 union {
51 char const *p_i;
52 char *p;
53 };
55
56typedef struct {
57 union {
58 uint8_t const *buff_i;
60 };
61 union {
62 uint8_t const *start_i;
63 uint8_t *start;
64 };
65 union {
66 uint8_t const *end_i;
67 uint8_t *end;
68 };
69 union {
70 uint8_t const *p_i;
71 uint8_t *p;
72 };
74
88
89#define SBUFF_CHAR_CLASS UINT8_MAX + 1
90
92{
93 fr_slen_t result;
94
95 /* result hex characters, plus the terminating '\0' */
96 if (result >= 0) __coverity_write_buffer_bytes__((void *)out->p_i, result + 1);
97
98 return result;
99}
100
102 bool no_trailing, uint8_t const alphabet[static SBUFF_CHAR_CLASS])
103{
104 fr_slen_t result;
105
106 /* result decoded bytes, no terminator */
107 if (result >= 0) __coverity_write_buffer_bytes__((void *)out->p_i, result);
108
109 return result;
110}
111
112/*
113 * Here we can use __coverity_writeall__(), which tells coverity "however big the thing
114 * pointed at is, consider it all written."
115 */
116
117typedef enum {
118 FR_TYPE_NULL = 0, //!< Invalid (uninitialised) attribute type.
119
120 FR_TYPE_STRING, //!< String of printable characters.
121 FR_TYPE_OCTETS, //!< Raw octets.
122
123 FR_TYPE_IPV4_ADDR, //!< 32 Bit IPv4 Address.
124 FR_TYPE_IPV4_PREFIX, //!< IPv4 Prefix.
125 FR_TYPE_IPV6_ADDR, //!< 128 Bit IPv6 Address.
126 FR_TYPE_IPV6_PREFIX, //!< IPv6 Prefix.
127 FR_TYPE_IFID, //!< Interface ID.
128 FR_TYPE_COMBO_IP_ADDR, //!< IPv4 or IPv6 address depending on length.
129 FR_TYPE_COMBO_IP_PREFIX, //!< IPv4 or IPv6 address prefix depending on length.
130 FR_TYPE_ETHERNET, //!< 48 Bit Mac-Address.
131
132 FR_TYPE_BOOL, //!< A truth value.
133
134 FR_TYPE_UINT8, //!< 8 Bit unsigned integer.
135 FR_TYPE_UINT16, //!< 16 Bit unsigned integer.
136 FR_TYPE_UINT32, //!< 32 Bit unsigned integer.
137 FR_TYPE_UINT64, //!< 64 Bit unsigned integer.
138
139
140 FR_TYPE_INT8, //!< 8 Bit signed integer.
141 FR_TYPE_INT16, //!< 16 Bit signed integer.
142 FR_TYPE_INT32, //!< 32 Bit signed integer.
143 FR_TYPE_INT64, //!< 64 Bit signed integer.
144
145 FR_TYPE_FLOAT32, //!< Single precision floating point.
146 FR_TYPE_FLOAT64, //!< Double precision floating point.
147
148 FR_TYPE_DATE, //!< Unix time stamp, always has value >2^31
149
150 FR_TYPE_TIME_DELTA, //!< A period of time measured in nanoseconds.
151
152 FR_TYPE_SIZE, //!< Unsigned integer capable of representing any memory
153 //!< address on the local system.
154
155 FR_TYPE_TLV, //!< Contains nested attributes.
156 FR_TYPE_STRUCT, //!< like TLV, but without T or L, and fixed-width children
157
158 FR_TYPE_VSA, //!< Vendor-Specific, for RADIUS attribute 26.
159 FR_TYPE_VENDOR, //!< Attribute that represents a vendor in the attribute tree.
160
161 FR_TYPE_GROUP, //!< A grouping of other attributes
162 FR_TYPE_VALUE_BOX, //!< A boxed value.
163
164 FR_TYPE_VOID, //!< User data. Should be a talloced chunk
165 ///< assigned to the ptr value of the union.
166
167 FR_TYPE_MAX //!< Number of defined data types.
169
170typedef struct {
172
173typedef struct {
175
176typedef struct {
178
180{
181 fr_sbuff_err_t result;
182
183 if (result == FR_SBUFF_OK) __coverity_write_buffer_bytes__((void *)out->p_i, len);
184
185 return result;
186}
187
189 bool const allowed[static SBUFF_CHAR_CLASS])
190{
191 fr_sbuff_err_t result;
192 size_t copied;
193
194 __coverity_write_buffer_bytes__((void *)out->p_i, copied + 1);
195 if (len) *len = copied;
196
197 return result;
198}
199
200typedef struct {
202typedef struct {
204
206 fr_sbuff_term_t const *tt,
207 fr_sbuff_unescape_rules_t const *u_rules)
208{
209 fr_sbuff_err_t result;
210 size_t copied;
211
212 __coverity_write_buffer_bytes__((void *)out->p_i, copied + 1);
213 if (len) *len = copied;
214
215 return result;
216}
217
219 fr_sbuff_term_t const *tt,
220 fr_sbuff_unescape_rules_t const *u_rules)
221{
222 fr_sbuff_err_t result;
223 size_t copied;
224
225 __coverity_write_buffer_bytes__((void *)out->p_i, copied + 1);
226 if (len) *len = copied;
227
228 return result;
229}
230
232 fr_dict_attr_t const *ancestor, fr_dict_attr_t const *da, bool numeric)
233{
234 ssize_t result;
235
236 if (result > 0) __coverity_write_buffer_bytes__((void *)out->p_i, result);
237
238 return result;
239}
240
241typedef struct {
242} fr_dict_t;
243
245{
246 ssize_t result;
247
248 if (result > 0) __coverity_write_buffer_bytes__((void *)out->p_i, result);
249
250 return result;
251}
252
253typedef struct {
254} request_t;
255
256typedef size_t (*xlat_escape_legacy_t)(request_t *request, char *out, size_t outlen, char const *in, void *arg);
257
258ssize_t xlat_eval(char *out, size_t outlen, request_t *request,
259 char const *fmt, xlat_escape_legacy_t escape, void const *escape_ctx)
260{
261 ssize_t result;
262
263 if (result > 0) __coverity_write_buffer_bytes__(out, result + 1);
264
265 return result;
266}
267
268typedef struct {
269} tmpl_t;
270
271typedef struct {
273
275 fr_sbuff_escape_rules_t const *e_rules)
276{
277 fr_slen_t result;
278
279 if (result >= 0) __coverity_write_buffer_bytes__((void *)out->p_i, result + 1);
280
281 return result;
282}
283
284#ifndef MD5_DIGEST_LENGTH
285# define MD5_DIGEST_LENGTH 16
286#endif
287
288void fr_md5_calc(uint8_t out[static MD5_DIGEST_LENGTH], uint8_t const *in, size_t inlen)
289{
290 __coverity_write_buffer_bytes__(out, MD5_DIGEST_LENGTH);
291}
292
293typedef struct {
295
296bool fr_radius_ok(uint8_t const *packet, size_t *packet_len_p,
297 uint32_t max_attributes, bool require_message_authenticator, decode_fail_t *reason)
298{
299 bool result;
300
301 if (result) {
302 __coverity_mark_pointee_as_sanitized__(&packet, TAINTED_SCALAR_GENERIC);
303 __coverity_mark_pointee_as_sanitized__(packet, TAINTED_SCALAR_GENERIC);
304 __coverity_mark_pointee_as_sanitized__(packet_len_p, TAINTED_SCALAR_GENERIC);
305 }
306 return result;
307}
308
309typedef struct {
311
312int fr_inet_pton4(fr_ipaddr_t *out, char const *value, ssize_t inlen, bool resolve, bool fallback, bool mask_bits)
313{
314 int result;
315
316 __coverity_writeall__(out);
317 return result;
318}
319
320/*
321 * talloc_get_type_abort() aborts unless ptr is a talloc chunk of the named
322 * type, so the pointer it returns is checked, even if ptr came from a read().
323 * A NULL ptr also aborts, because the talloc abort handlers in
324 * src/lib/util/debug.c never return.
325 */
326void *_talloc_get_type_abort(const void *ptr, const char *name, const char *location)
327{
328 if (!ptr) __coverity_panic__();
329
330 __coverity_mark_pointee_as_sanitized__(&ptr, TAINTED_SCALAR_GENERIC);
331 return (void *)ptr;
332}
333
334/*
335 * from src/lib/util/test/acutest.h
336 *
337 * acutest_check_() returns the condition it was passed, so TEST_ASSERT()
338 * only reaches the noreturn acutest_abort_() when the condition is false.
339 * Without the model the analyser does not carry the condition through the
340 * call, and follows the failure path past the assertion into the code the
341 * assertion guards.
342 */
343int acutest_check_(int cond, char const *file, int line, char const *fmt, ...)
344{
345 return cond;
346}
347
349{
350 __coverity_panic__();
351}
352
353/*
354 * from src/lib/io/atomic_queue.c
355 *
356 * atomic_ring_segment_publish() stores the new segment into h->next and
357 * ring->head with atomic stores, which the analyser does not treat as
358 * publishing the pointer, so it reports the segment as leaked when the
359 * caller returns. The consumer frees the segment once it advances past.
360 */
361typedef struct {
363
364typedef struct {
366
int n
Definition acutest.h:642
static int const char * fmt
Definition acutest.h:638
void int line
Definition acutest.h:810
static uint8_t request[4]
Values of the encryption flags.
Test enumeration values.
Definition dict_test.h:92
IPv4/6 prefix.
#define MD5_DIGEST_LENGTH
fr_sbuff_err_t fr_sbuff_out_bstrncpy_exact(fr_sbuff_t *out, fr_sbuff_t *in, size_t len)
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)
unsigned short uint16_t
#define SBUFF_CHAR_CLASS
size_t(* xlat_escape_legacy_t)(request_t *request, char *out, size_t outlen, char const *in, void *arg)
fr_type_t
@ FR_TYPE_TIME_DELTA
A period of time measured in nanoseconds.
@ FR_TYPE_FLOAT32
Single precision floating point.
@ FR_TYPE_IPV4_ADDR
32 Bit IPv4 Address.
@ FR_TYPE_INT8
8 Bit signed integer.
@ FR_TYPE_TLV
Contains nested attributes.
@ FR_TYPE_ETHERNET
48 Bit Mac-Address.
@ FR_TYPE_IPV6_PREFIX
IPv6 Prefix.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_MAX
Number of defined data types.
@ FR_TYPE_NULL
Invalid (uninitialised) attribute type.
@ FR_TYPE_UINT16
16 Bit unsigned integer.
@ FR_TYPE_INT64
64 Bit signed integer.
@ FR_TYPE_INT16
16 Bit signed integer.
@ FR_TYPE_DATE
Unix time stamp, always has value >2^31.
@ FR_TYPE_COMBO_IP_PREFIX
IPv4 or IPv6 address prefix depending on length.
@ FR_TYPE_VALUE_BOX
A boxed value.
@ FR_TYPE_UINT8
8 Bit unsigned integer.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_STRUCT
like TLV, but without T or L, and fixed-width children
@ FR_TYPE_INT32
32 Bit signed integer.
@ FR_TYPE_VENDOR
Attribute that represents a vendor in the attribute tree.
@ FR_TYPE_UINT64
64 Bit unsigned integer.
@ FR_TYPE_IPV6_ADDR
128 Bit IPv6 Address.
@ FR_TYPE_IPV4_PREFIX
IPv4 Prefix.
@ FR_TYPE_VOID
User data.
@ FR_TYPE_BOOL
A truth value.
@ FR_TYPE_SIZE
Unsigned integer capable of representing any memory address on the local system.
@ FR_TYPE_VSA
Vendor-Specific, for RADIUS attribute 26.
@ FR_TYPE_COMBO_IP_ADDR
IPv4 or IPv6 address depending on length.
@ FR_TYPE_IFID
Interface ID.
@ FR_TYPE_OCTETS
Raw octets.
@ FR_TYPE_GROUP
A grouping of other attributes.
@ FR_TYPE_FLOAT64
Double precision floating point.
unsigned int uint32_t
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)
int fr_inet_pton4(fr_ipaddr_t *out, char const *value, ssize_t inlen, bool resolve, bool fallback, bool mask_bits)
int acutest_check_(int cond, char const *file, int line, char const *fmt,...)
long int ssize_t
fr_sbuff_err_t fr_sbuff_out_bstrncpy_allowed(size_t *len, fr_sbuff_t *out, fr_sbuff_t *in, size_t max, bool const allowed[static SBUFF_CHAR_CLASS])
void acutest_abort_(void)
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)
unsigned char bool
ssize_t xlat_eval(char *out, size_t outlen, request_t *request, char const *fmt, xlat_escape_legacy_t escape, void const *escape_ctx)
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.
void atomic_ring_segment_publish(fr_atomic_ring_t *ring, fr_atomic_ring_segment_t *h, fr_atomic_ring_segment_t *n)
fr_sbuff_err_t
@ FR_SBUFF_ERR_INPUT_EMPTY
@ FR_SBUFF_ERR_FORMAT
@ FR_SBUFF_ERR_TRAILING
@ FR_SBUFF_ERR_NO_SPACE
@ FR_SBUFF_ERR_UNINITIALISED
@ FR_SBUFF_ERR_EXTEND
@ FR_SBUFF_ERR_UNDERFLOW
@ FR_SBUFF_ERR_OVERFLOW
@ FR_SBUFF_ERR_INPUT_SHORT
@ FR_SBUFF_ERR_NOT_FOUND
@ FR_SBUFF_OK
fr_sbuff_err_t fr_sbuff_out_bstrncpy_until(size_t *len, fr_sbuff_t *out, fr_sbuff_t *in, size_t max, fr_sbuff_term_t const *tt, fr_sbuff_unescape_rules_t const *u_rules)
fr_slen_t fr_base16_decode_nstd(fr_sbuff_err_t *err, fr_dbuff_t *out, fr_sbuff_t *in, bool no_trailing, uint8_t const alphabet[static SBUFF_CHAR_CLASS])
unsigned char uint8_t
fr_sbuff_err_t fr_sbuff_out_unescape_until(size_t *len, fr_sbuff_t *out, fr_sbuff_t *in, size_t max, fr_sbuff_term_t const *tt, fr_sbuff_unescape_rules_t const *u_rules)
void * _talloc_get_type_abort(const void *ptr, const char *name, const char *location)
ssize_t fr_slen_t
fr_slen_t tmpl_print(fr_sbuff_t *out, tmpl_t const *vpt, fr_sbuff_escape_rules_t const *e_rules)
unsigned long int size_t
fr_slen_t fr_base16_encode_nstd(fr_sbuff_t *out, fr_dbuff_t *in, char const alphabet[static SBUFF_CHAR_CLASS])
static char const * name
Set of terminal elements.
Set of parsing rules for *unescape_until functions.
static fr_slen_t vpt
Definition tmpl.h:1300
static char buff[sizeof("18446744073709551615")+3]
Definition size_tests.c:37
fr_aka_sim_id_type_t type
static fr_sbuff_err_t char size_t fr_sbuff_t * in
Definition value.h:1061
static fr_sbuff_err_t char size_t fr_sbuff_t size_t max
Definition value.h:1061
static fr_sbuff_err_t char ** out
Definition value.h:1061
static fr_sbuff_err_t char size_t * len
Definition value.h:1061