Coverage Report

Created: 2024-05-20 01:00

/src/openiked-portable/regress/parser-libfuzzer/common.c
Line
Count
Source (jump to first uncovered line)
1
/*  $OpenBSD: common.c,v 1.9 2020/11/26 22:29:32 tobhe Exp $ */
2
/*
3
 * A bunch of stub functions so we can compile and link ikev2_pld.c
4
 * in a standalone program for testing purposes.
5
 *
6
 * Placed in the public domain
7
 */
8
9
#include <sys/socket.h>
10
#include <sys/time.h>
11
#include <sys/uio.h>
12
13
#include <event.h>
14
#include <limits.h>
15
#include <string.h>
16
17
#include "iked.h"
18
#include "types.h"
19
20
273k
#define IKEV2_FLAG_INITIATOR            0x08    /* Sent by the initiator */
21
22
int  eap_parse(struct iked *, const struct iked_sa *,
23
      struct iked_message *, void *, int);
24
int  ikev2_msg_frompeer(struct iked_message *);
25
int  ikev2_send_ike_e(struct iked *, struct iked_sa *, struct ibuf *,
26
      u_int8_t, u_int8_t, int);
27
void   ikev2_ikesa_recv_delete(struct iked *, struct iked_sa *);
28
struct iked_childsa *
29
   childsa_lookup(struct iked_sa *, u_int64_t, u_int8_t);
30
int   ikev2_childsa_delete(struct iked *, struct iked_sa *,
31
      u_int8_t, u_int64_t, u_int64_t *, int);
32
int  sa_stateok(const struct iked_sa *, int);
33
void   sa_state(struct iked *, struct iked_sa *, int);
34
void   ikev2_disable_rekeying(struct iked *, struct iked_sa *);
35
void   ikev2_init_ike_sa(struct iked *, void *);
36
struct dh_group *
37
   group_get(u_int32_t);
38
void   timer_set(struct iked *, struct iked_timer *,
39
       void (*)(struct iked *, void *), void *);
40
void   timer_add(struct iked *, struct iked_timer *, int);
41
void   timer_del(struct iked *, struct iked_timer *);
42
ssize_t  ikev2_nat_detection(struct iked *, struct iked_message *,
43
       void *, size_t, u_int, int);
44
int  ca_setreq(struct iked *, struct iked_sa *, struct iked_static_id *,
45
       u_int8_t, u_int8_t, u_int8_t *, size_t, enum privsep_procid);
46
int  ikev2_print_id(struct iked_id *, char *, size_t);
47
int  config_add_transform(struct iked_proposal *, u_int, u_int, u_int,
48
       u_int);
49
struct iked_proposal *
50
   config_add_proposal(struct iked_proposals *, u_int, u_int);
51
void   config_free_proposal(struct iked_proposals *, struct iked_proposal *);
52
int  ikev2_send_informational(struct iked *, struct iked_message *);
53
struct ibuf *
54
   ikev2_msg_decrypt(struct iked *, struct iked_sa *, struct ibuf *,
55
       struct ibuf *);
56
void ikev2_msg_cleanup(struct iked *, struct iked_message *);
57
58
int
59
eap_parse(struct iked *env, const struct iked_sa *sa, struct iked_message *msg,
60
    void *data, int response)
61
5.09k
{
62
5.09k
  return (0);
63
5.09k
}
64
65
/* Copied from ikev2_msg.c for better coverage */
66
int
67
ikev2_msg_frompeer(struct iked_message *msg)
68
273k
{
69
273k
  struct iked_sa    *sa = msg->msg_sa;
70
273k
  struct ike_header *hdr;
71
72
273k
  msg = msg->msg_parent;
73
74
273k
  if (sa == NULL ||
75
273k
      (hdr = ibuf_seek(msg->msg_data, 0, sizeof(*hdr))) == NULL)
76
0
    return (0);
77
78
273k
  if (!sa->sa_hdr.sh_initiator &&
79
273k
      (hdr->ike_flags & IKEV2_FLAG_INITIATOR))
80
69.0k
    return (1);
81
204k
  else if (sa->sa_hdr.sh_initiator &&
82
204k
      (hdr->ike_flags & IKEV2_FLAG_INITIATOR) == 0)
83
0
    return (1);
84
85
204k
  return (0);
86
273k
}
87
88
int
89
ikev2_send_ike_e(struct iked *env, struct iked_sa *sa, struct ibuf *buf,
90
    u_int8_t firstpayload, u_int8_t exchange, int response)
91
0
{
92
0
  return (0);
93
0
}
94
95
void
96
ikev2_ikesa_recv_delete(struct iked *env, struct iked_sa *sa)
97
0
{
98
0
}
99
100
const char *
101
ikev2_ikesa_info(uint64_t spi, const char *msg)
102
15.5k
{
103
15.5k
  return "";
104
15.5k
}
105
106
struct iked_childsa *
107
childsa_lookup(struct iked_sa *a, u_int64_t b, u_int8_t c)
108
0
{
109
0
  return (NULL);
110
0
}
111
112
int
113
ikev2_childsa_delete(struct iked *a, struct iked_sa *b, u_int8_t c,
114
    u_int64_t d, u_int64_t *e , int f)
115
0
{
116
0
  return (0);
117
0
}
118
119
int
120
sa_stateok(const struct iked_sa *a, int b)
121
149
{
122
149
  return (0);
123
149
}
124
125
void
126
sa_state(struct iked * a, struct iked_sa *b, int c)
127
0
{
128
0
}
129
130
void
131
ikev2_disable_rekeying(struct iked *a, struct iked_sa *b)
132
0
{
133
0
}
134
135
void
136
ikev2_init_ike_sa(struct iked *a, void *b)
137
0
{
138
0
}
139
140
const struct group_id *
141
group_getid(u_int32_t id)
142
0
{
143
0
  return (NULL);
144
0
}
145
146
void
147
timer_set(struct iked *env, struct iked_timer *tmr,
148
    void (*cb)(struct iked *, void *), void *arg)
149
0
{
150
0
}
151
152
void
153
timer_add(struct iked *env, struct iked_timer *tmr, int timeout)
154
0
{
155
0
}
156
157
void
158
timer_del(struct iked *env, struct iked_timer *tmr)
159
0
{
160
0
}
161
162
ssize_t
163
ikev2_nat_detection(struct iked *env, struct iked_message *msg,
164
    void *ptr, size_t len, u_int type, int frompeer)
165
26.0k
{
166
26.0k
  bzero(ptr, len);
167
26.0k
  return (0);
168
26.0k
}
169
170
int
171
ca_setreq(struct iked *env, struct iked_sa *sh, struct iked_static_id *localid,
172
    u_int8_t type, u_int8_t more, u_int8_t *data, size_t len,
173
    enum privsep_procid procid)
174
0
{
175
0
  return (0);
176
0
}
177
178
int
179
ikev2_print_id(struct iked_id *id, char *idstr, size_t idstrlen)
180
8.38k
{
181
8.38k
  return (0);
182
8.38k
}
183
184
int
185
config_add_transform(struct iked_proposal *prop, u_int type,
186
    u_int id, u_int length, u_int keylength)
187
0
{
188
0
  return (0);
189
0
}
190
191
struct iked_proposal *
192
config_add_proposal(struct iked_proposals *head, u_int id, u_int proto)
193
69
{
194
69
  return (NULL);
195
69
}
196
197
void
198
config_free_proposal(struct iked_proposals *head, struct iked_proposal *prop)
199
0
{
200
0
  return;
201
0
}
202
203
void config_free_fragments(struct iked_frag *frag)
204
0
{
205
0
  return;
206
0
}
207
208
int
209
ikev2_send_informational(struct iked *env, struct iked_message *msg)
210
771
{
211
771
  return (0);
212
771
}
213
214
struct ibuf *
215
ikev2_msg_decrypt(struct iked *env, struct iked_sa *sa,
216
    struct ibuf *msg, struct ibuf *src)
217
0
{
218
0
  if (src == NULL){
219
0
                fprintf(stderr, "%s\n", "msg_decrypt: src == NULL!");
220
0
                exit(-1);
221
0
        }
222
223
  /*
224
   * Free src as caller uses ikev2_msg_decrypt() like this:
225
   * src = ikev2_msg_decrypt(..., src);
226
   */
227
0
  ibuf_free(src); 
228
0
  return (NULL);
229
0
}
230
231
void
232
ikev2_ike_sa_setreason(struct iked_sa *sa, char *r)
233
0
{
234
0
}
235
236
void
237
ikev2_msg_dispose(struct iked *env, struct iked_msgqueue *queue,
238
    struct iked_msg_retransmit *mr)
239
0
{
240
0
}
241
242
struct iked_msg_retransmit *
243
ikev2_msg_lookup(struct iked *env, struct iked_msgqueue *queue,
244
    struct iked_message *msg, uint8_t exchange)
245
0
{
246
0
  return NULL;
247
0
}
248
249
/* copied from ikev2_msg.c */
250
void
251
ikev2_msg_cleanup(struct iked *env, struct iked_message *msg)
252
16.0k
{
253
16.0k
  struct iked_certreq *cr;
254
16.0k
  struct iked_proposal *prop, *proptmp;
255
16.0k
  int      i;
256
257
16.0k
  if (msg == msg->msg_parent) {
258
16.0k
    ibuf_free(msg->msg_nonce);
259
16.0k
    ibuf_free(msg->msg_ke);
260
16.0k
    ibuf_free(msg->msg_auth.id_buf);
261
16.0k
    ibuf_free(msg->msg_peerid.id_buf);
262
16.0k
    ibuf_free(msg->msg_localid.id_buf);
263
16.0k
    ibuf_free(msg->msg_cert.id_buf);
264
64.3k
    for (i = 0; i < IKED_SCERT_MAX; i++)
265
48.2k
      ibuf_free(msg->msg_scert[i].id_buf);
266
16.0k
    ibuf_free(msg->msg_cookie);
267
16.0k
    ibuf_free(msg->msg_cookie2);
268
16.0k
    ibuf_free(msg->msg_del_buf);
269
16.0k
    free(msg->msg_eap.eam_user);
270
16.0k
    free(msg->msg_cp_addr);
271
16.0k
    free(msg->msg_cp_addr6);
272
16.0k
    free(msg->msg_cp_dns);
273
274
16.0k
    TAILQ_FOREACH_SAFE(prop, &msg->msg_proposals, prop_entry,
275
16.0k
        proptmp) {
276
0
      TAILQ_REMOVE(&msg->msg_proposals, prop, prop_entry);
277
0
      if (prop->prop_nxforms)
278
0
        free(prop->prop_xforms);
279
0
      free(prop);
280
0
    }
281
282
16.0k
    msg->msg_nonce = NULL;
283
16.0k
    msg->msg_ke = NULL;
284
16.0k
    msg->msg_auth.id_buf = NULL;
285
16.0k
    msg->msg_peerid.id_buf = NULL;
286
16.0k
    msg->msg_localid.id_buf = NULL;
287
16.0k
    msg->msg_cert.id_buf = NULL;
288
64.3k
    for (i = 0; i < IKED_SCERT_MAX; i++)
289
48.2k
      msg->msg_scert[i].id_buf = NULL;
290
16.0k
    msg->msg_cookie = NULL;
291
16.0k
    msg->msg_cookie2 = NULL;
292
16.0k
    msg->msg_del_buf = NULL;
293
16.0k
    msg->msg_eap.eam_user = NULL;
294
16.0k
    msg->msg_cp_addr = NULL;
295
16.0k
    msg->msg_cp_addr6 = NULL;
296
16.0k
    msg->msg_cp_dns = NULL;
297
298
17.1k
    while ((cr = SIMPLEQ_FIRST(&msg->msg_certreqs))) {
299
1.06k
      ibuf_free(cr->cr_data);
300
1.06k
      SIMPLEQ_REMOVE_HEAD(&msg->msg_certreqs, cr_entry);
301
1.06k
      free(cr);
302
1.06k
    }
303
16.0k
  }
304
305
16.0k
  if (msg->msg_data != NULL) {
306
16.0k
    ibuf_free(msg->msg_data);
307
16.0k
    msg->msg_data = NULL;
308
16.0k
  }
309
16.0k
}