The FreeRADIUS server $Id: f3670dba8951ca10eb4948feb3dc3db9423a334f $
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 unsigned int mode_t;
22typedef long long int off_t;
23
24typedef long int ssize_t;
25typedef unsigned long int size_t;
26
27typedef union {
29
30typedef unsigned char uint8_t;
31typedef unsigned short uint16_t;
32#define UINT8_MAX 255
33typedef unsigned int uint32_t;
34
36
37/*
38 * Field order matches the real structs, so p is at the same offset.
39 */
40typedef struct {
41 char *buff;
42 char *start;
43 char *end;
44 char *p;
46
53
67
68#define SBUFF_CHAR_CLASS UINT8_MAX + 1
69
71{
72 fr_slen_t result;
73
74 /* result hex characters, plus the terminating '\0' */
75 if (result >= 0) __coverity_write_buffer_bytes__(out->p, result + 1);
76
77 return result;
78}
79
81 bool no_trailing, uint8_t const alphabet[static SBUFF_CHAR_CLASS])
82{
83 fr_slen_t result;
84
85 /* result decoded bytes, no terminator */
86 if (result >= 0) __coverity_write_buffer_bytes__(out->p, result);
87
88 return result;
89}
90
91/*
92 * Here we can use __coverity_writeall__(), which tells coverity "however big the thing
93 * pointed at is, consider it all written."
94 */
95
96typedef enum {
97 FR_TYPE_NULL = 0, //!< Invalid (uninitialised) attribute type.
98
99 FR_TYPE_STRING, //!< String of printable characters.
100 FR_TYPE_OCTETS, //!< Raw octets.
101
102 FR_TYPE_IPV4_ADDR, //!< 32 Bit IPv4 Address.
103 FR_TYPE_IPV4_PREFIX, //!< IPv4 Prefix.
104 FR_TYPE_IPV6_ADDR, //!< 128 Bit IPv6 Address.
105 FR_TYPE_IPV6_PREFIX, //!< IPv6 Prefix.
106 FR_TYPE_IFID, //!< Interface ID.
107 FR_TYPE_COMBO_IP_ADDR, //!< IPv4 or IPv6 address depending on length.
108 FR_TYPE_COMBO_IP_PREFIX, //!< IPv4 or IPv6 address prefix depending on length.
109 FR_TYPE_ETHERNET, //!< 48 Bit Mac-Address.
110
111 FR_TYPE_BOOL, //!< A truth value.
112
113 FR_TYPE_UINT8, //!< 8 Bit unsigned integer.
114 FR_TYPE_UINT16, //!< 16 Bit unsigned integer.
115 FR_TYPE_UINT32, //!< 32 Bit unsigned integer.
116 FR_TYPE_UINT64, //!< 64 Bit unsigned integer.
117
118
119 FR_TYPE_INT8, //!< 8 Bit signed integer.
120 FR_TYPE_INT16, //!< 16 Bit signed integer.
121 FR_TYPE_INT32, //!< 32 Bit signed integer.
122 FR_TYPE_INT64, //!< 64 Bit signed integer.
123
124 FR_TYPE_FLOAT32, //!< Single precision floating point.
125 FR_TYPE_FLOAT64, //!< Double precision floating point.
126
127 FR_TYPE_DATE, //!< Unix time stamp, always has value >2^31
128
129 FR_TYPE_TIME_DELTA, //!< A period of time measured in nanoseconds.
130
131 FR_TYPE_SIZE, //!< Unsigned integer capable of representing any memory
132 //!< address on the local system.
133
134 FR_TYPE_TLV, //!< Contains nested attributes.
135 FR_TYPE_STRUCT, //!< like TLV, but without T or L, and fixed-width children
136
137 FR_TYPE_VSA, //!< Vendor-Specific, for RADIUS attribute 26.
138 FR_TYPE_VENDOR, //!< Attribute that represents a vendor in the attribute tree.
139
140 FR_TYPE_GROUP, //!< A grouping of other attributes
141 FR_TYPE_VALUE_BOX, //!< A boxed value.
142
143 FR_TYPE_VOID, //!< User data. Should be a talloced chunk
144 ///< assigned to the ptr value of the union.
145
146 FR_TYPE_MAX //!< Number of defined data types.
148
149typedef struct {
151
152typedef struct {
154
155typedef struct {
157
159{
160 fr_sbuff_err_t result;
161
162 if (result == FR_SBUFF_OK) __coverity_write_buffer_bytes__(out->p, len);
163
164 return result;
165}
166
168 bool const allowed[static SBUFF_CHAR_CLASS])
169{
170 fr_sbuff_err_t result;
171 size_t copied;
172
173 __coverity_write_buffer_bytes__(out->p, copied + 1);
174 if (len) *len = copied;
175
176 return result;
177}
178
179typedef struct {
181typedef struct {
183
185 fr_sbuff_term_t const *tt,
186 fr_sbuff_unescape_rules_t const *u_rules)
187{
188 fr_sbuff_err_t result;
189 size_t copied;
190
191 __coverity_write_buffer_bytes__(out->p, copied + 1);
192 if (len) *len = copied;
193
194 return result;
195}
196
198 fr_sbuff_term_t const *tt,
199 fr_sbuff_unescape_rules_t const *u_rules)
200{
201 fr_sbuff_err_t result;
202 size_t copied;
203
204 __coverity_write_buffer_bytes__(out->p, copied + 1);
205 if (len) *len = copied;
206
207 return result;
208}
209
211 fr_dict_attr_t const *ancestor, fr_dict_attr_t const *da, bool numeric)
212{
213 ssize_t result;
214
215 if (result > 0) __coverity_write_buffer_bytes__(out->p, result);
216
217 return result;
218}
219
220typedef struct {
221} fr_dict_t;
222
224{
225 ssize_t result;
226
227 if (result > 0) __coverity_write_buffer_bytes__(out->p, result);
228
229 return result;
230}
231
232typedef struct {
233} request_t;
234
235typedef size_t (*xlat_escape_legacy_t)(request_t *request, char *out, size_t outlen, char const *in, void *arg);
236
237ssize_t xlat_eval(char *out, size_t outlen, request_t *request,
238 char const *fmt, xlat_escape_legacy_t escape, void const *escape_ctx)
239{
240 ssize_t result;
241
242 if (result > 0) __coverity_write_buffer_bytes__(out, result + 1);
243
244 return result;
245}
246
247typedef struct {
248} tmpl_t;
249
250typedef struct {
252
254 fr_sbuff_escape_rules_t const *e_rules)
255{
256 fr_slen_t result;
257
258 if (result >= 0) __coverity_write_buffer_bytes__(out->p, result + 1);
259
260 return result;
261}
262
263#ifndef MD5_DIGEST_LENGTH
264# define MD5_DIGEST_LENGTH 16
265#endif
266
267void fr_md5_calc(uint8_t out[static MD5_DIGEST_LENGTH], uint8_t const *in, size_t inlen)
268{
269 __coverity_write_buffer_bytes__(out, MD5_DIGEST_LENGTH);
270}
271
272typedef struct {
274
275bool fr_radius_ok(uint8_t const *packet, size_t *packet_len_p,
276 uint32_t max_attributes, bool require_message_authenticator, decode_fail_t *reason)
277{
278 bool result;
279
280 if (result) {
281 __coverity_mark_pointee_as_sanitized__(&packet, TAINTED_SCALAR_GENERIC);
282 __coverity_mark_pointee_as_sanitized__(packet, TAINTED_SCALAR_GENERIC);
283 __coverity_mark_pointee_as_sanitized__(packet_len_p, TAINTED_SCALAR_GENERIC);
284 }
285 return result;
286}
287
288typedef struct {
290
291int fr_inet_pton4(fr_ipaddr_t *out, char const *value, ssize_t inlen, bool resolve, bool fallback, bool mask_bits)
292{
293 int result;
294
295 __coverity_writeall__(out);
296 return result;
297}
298
299/*
300 * talloc_get_type_abort() aborts unless ptr is a talloc chunk of the named
301 * type, so the pointer it returns is checked, even if ptr came from a read().
302 * A NULL ptr also aborts, because the talloc abort handlers in
303 * src/lib/util/debug.c never return.
304 */
305void *_talloc_get_type_abort(const void *ptr, const char *name, const char *location)
306{
307 if (!ptr) __coverity_panic__();
308
309 __coverity_mark_pointee_as_sanitized__(&ptr, TAINTED_SCALAR_GENERIC);
310 return (void *)ptr;
311}
312
313/*
314 * from src/lib/server/exfile.[ch]
315 *
316 * In the model, exfile_open() returns holding ef->mutex only when the
317 * returned file descriptor is >= 0, and exfile_close() always releases
318 * ef->mutex. The real functions take ef->mutex only when ef->locking is
319 * true. Callers pair every successful exfile_open() with exfile_close()
320 * whether or not ef->locking is true, so the model takes and releases
321 * ef->mutex unconditionally.
322 */
326
327int exfile_open(exfile_t *ef, char const *filename, mode_t permissions, int flags, off_t *offset)
328{
329 int result;
330 off_t real_offset;
331
332 if (result >= 0) {
333 __coverity_exclusive_lock_acquire__(&ef->mutex);
334 if (offset) *offset = real_offset;
335 }
336
337 return result;
338}
339
340int exfile_close(exfile_t *ef, int fd)
341{
342 int result;
343
344 __coverity_exclusive_lock_release__(&ef->mutex);
345
346 return result;
347}
348
349/*
350 * from src/lib/util/test/acutest.h
351 *
352 * acutest_check_() returns the condition it was passed, so TEST_ASSERT()
353 * only reaches the noreturn acutest_abort_() when the condition is false.
354 * Without the model the analyser does not carry the condition through the
355 * call, and follows the failure path past the assertion into the code the
356 * assertion guards.
357 */
358int acutest_check_(int cond, char const *file, int line, char const *fmt, ...)
359{
360 return cond;
361}
362
364{
365 __coverity_panic__();
366}
367
368/*
369 * from src/lib/io/atomic_queue.c
370 *
371 * atomic_ring_segment_publish() stores the new segment into h->next and
372 * ring->head with atomic stores, which the analyser does not treat as
373 * publishing the pointer, so it reports the segment as leaked when the
374 * caller returns. The consumer frees the segment once it advances past.
375 */
376typedef struct {
378
379typedef struct {
381
int n
Definition acutest.h:636
static int const char * fmt
Definition acutest.h:632
void int line
Definition acutest.h:804
static uint8_t request[4]
Values of the encryption flags.
Test enumeration values.
Definition dict_test.h:92
pthread_mutex_t mutex
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.
char * buff
uint8_t * p
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,...)
uint8_t * end
uint8_t * start
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])
char * start
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
int exfile_open(exfile_t *ef, char const *filename, mode_t permissions, int flags, off_t *offset)
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
uint8_t * buff
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)
unsigned int mode_t
ssize_t fr_slen_t
struct exfile_s exfile_t
long long int off_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])
int exfile_close(exfile_t *ef, int fd)
static char const * name
Set of terminal elements.
Set of parsing rules for *unescape_until functions.
static fr_slen_t vpt
Definition tmpl.h:1298
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