Coverage Report

Created: 2025-12-31 06:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/resiprocate/resip/stack/test/fuzzStack.cxx
Line
Count
Source
1
#include "rutil/DataStream.hxx"
2
#include "rutil/Logger.hxx"
3
4
#include "resip/stack/Auth.hxx"
5
#include "resip/stack/CSeqCategory.hxx"
6
#include "resip/stack/CallId.hxx"
7
#include "resip/stack/CpimContents.hxx"
8
#include "resip/stack/DateCategory.hxx"
9
#include "resip/stack/DialogInfoContents.hxx"
10
#include "resip/stack/DtmfPayloadContents.hxx"
11
#include "resip/stack/ExpiresCategory.hxx"
12
#include "resip/stack/GenericPidfContents.hxx"
13
#include "resip/stack/GenericUri.hxx"
14
#include "resip/stack/IntegerCategory.hxx"
15
#include "resip/stack/InvalidContents.hxx"
16
#include "resip/stack/MessageWaitingContents.hxx"
17
#include "resip/stack/Mime.hxx"
18
#include "resip/stack/MultipartMixedContents.hxx"
19
#include "resip/stack/NameAddr.hxx"
20
#include "resip/stack/OctetContents.hxx"
21
#include "resip/stack/GenericPidfContents.hxx"
22
#include "resip/stack/Pkcs7Contents.hxx"
23
#include "resip/stack/Pkcs8Contents.hxx"
24
#include "resip/stack/PlainContents.hxx"
25
#include "resip/stack/PrivacyCategory.hxx"
26
#include "resip/stack/RAckCategory.hxx"
27
#include "resip/stack/RequestLine.hxx"
28
#include "resip/stack/Rlmi.hxx"
29
#include "resip/stack/SdpContents.hxx"
30
#include "resip/stack/SipFrag.hxx"
31
#include "resip/stack/StatusLine.hxx"
32
#include "resip/stack/StringCategory.hxx"
33
#include "resip/stack/Token.hxx"
34
#include "resip/stack/TokenOrQuotedStringCategory.hxx"
35
#include "resip/stack/UInt32Category.hxx"
36
#include "resip/stack/Uri.hxx"
37
#include "resip/stack/Via.hxx"
38
#include "resip/stack/WarningCategory.hxx"
39
#include "resip/stack/X509Contents.hxx"
40
41
#include "TestSupport.hxx"
42
43
static void fuzzAuth(const resip::HeaderFieldValue& hfv)
44
6.05k
{
45
6.05k
    resip::Auth payload(hfv, resip::Headers::UNKNOWN);
46
6.05k
    try
47
6.05k
    {
48
6.05k
        payload.checkParsed();
49
6.05k
    }
50
6.05k
    catch (const resip::ParseException&)
51
6.05k
    {
52
392
    }
53
6.05k
}
54
55
static void fuzzCSeqCategory(const resip::HeaderFieldValue& hfv)
56
6.05k
{
57
6.05k
    resip::CSeqCategory payload(hfv, resip::Headers::UNKNOWN);
58
6.05k
    try
59
6.05k
    {
60
6.05k
        payload.checkParsed();
61
6.05k
    }
62
6.05k
    catch (const resip::ParseException&)
63
6.05k
    {
64
5.70k
    }
65
6.05k
}
66
67
static void fuzzCpimContents(const resip::HeaderFieldValue& hfv)
68
6.05k
{
69
6.05k
    static const resip::Mime type("message", "cpim");
70
6.05k
    resip::CpimContents payload(hfv, type);
71
6.05k
    try
72
6.05k
    {
73
6.05k
        payload.checkParsed();
74
6.05k
    }
75
6.05k
    catch (const resip::ParseException&)
76
6.05k
    {
77
0
    }
78
6.05k
}
79
80
static void fuzzCallId(const resip::HeaderFieldValue& hfv)
81
6.05k
{
82
6.05k
    resip::CallId payload(hfv, resip::Headers::UNKNOWN);
83
6.05k
    try
84
6.05k
    {
85
6.05k
        payload.checkParsed();
86
6.05k
    }
87
6.05k
    catch (const resip::ParseException&)
88
6.05k
    {
89
211
    }
90
6.05k
}
91
92
static void fuzzDtmfPayloadContents(const resip::HeaderFieldValue& hfv)
93
6.05k
{
94
6.05k
  static const resip::Mime type("application", "dtmf-relay");
95
6.05k
  resip::DtmfPayloadContents payload(hfv, type);
96
6.05k
  try
97
6.05k
  {
98
6.05k
    payload.checkParsed();
99
6.05k
  }
100
6.05k
  catch (const resip::ParseException&)
101
6.05k
  {
102
6.03k
  }
103
6.05k
}
104
105
static void fuzzDateCategory(const resip::HeaderFieldValue& hfv)
106
6.05k
{
107
6.05k
    resip::DateCategory payload(hfv, resip::Headers::UNKNOWN);
108
6.05k
    try
109
6.05k
    {
110
6.05k
        payload.checkParsed();
111
6.05k
    }
112
6.05k
    catch (const resip::ParseException&)
113
6.05k
    {
114
6.04k
    }
115
6.05k
}
116
117
static void fuzzDialogInfoContents(const resip::HeaderFieldValue& hfv)
118
0
{
119
0
    static const resip::Mime type("application", "sdp");
120
0
    resip::DialogInfoContents payload(hfv, type);
121
0
    try
122
0
    {
123
0
        payload.checkParsed();
124
0
    }
125
0
    catch (const resip::ParseException&)
126
0
    {
127
0
    }
128
0
}
129
130
static void fuzzExpiresCategory(const resip::HeaderFieldValue& hfv)
131
6.05k
{
132
6.05k
    resip::ExpiresCategory payload(hfv, resip::Headers::UNKNOWN);
133
6.05k
    try
134
6.05k
    {
135
6.05k
        payload.checkParsed();
136
6.05k
    }
137
6.05k
    catch (const resip::ParseException&)
138
6.05k
    {
139
225
    }
140
6.05k
}
141
142
static void fuzzGenericPidfContents(const resip::HeaderFieldValue& hfv)
143
0
{
144
0
    static const resip::Mime type("application", "pidf+xml");
145
0
    resip::GenericPidfContents payload(hfv, type);
146
0
    try
147
0
    {
148
0
        payload.checkParsed();
149
0
    }
150
0
    catch (const resip::ParseException&)
151
0
    {
152
0
    }
153
0
}
154
155
static void fuzzGenericUri(const resip::HeaderFieldValue& hfv)
156
6.05k
{
157
6.05k
    resip::GenericURI payload(hfv, resip::Headers::UNKNOWN);
158
6.05k
    try
159
6.05k
    {
160
6.05k
        payload.checkParsed();
161
6.05k
    }
162
6.05k
    catch (const resip::ParseException&)
163
6.05k
    {
164
6.03k
    }
165
6.05k
}
166
167
static void fuzzIntegerCategory(const resip::HeaderFieldValue& hfv)
168
6.05k
{
169
6.05k
    resip::IntegerCategory payload(hfv, resip::Headers::UNKNOWN);
170
6.05k
    try
171
6.05k
    {
172
6.05k
        payload.checkParsed();
173
6.05k
    }
174
6.05k
    catch (const resip::ParseException&)
175
6.05k
    {
176
5.66k
    }
177
6.05k
}
178
179
static void fuzzInvalidContents(const resip::HeaderFieldValue& hfv)
180
6.05k
{
181
6.05k
    static const resip::Mime type("Invalid", "Invalid");
182
6.05k
    resip::InvalidContents payload(hfv, type, type);
183
6.05k
    try
184
6.05k
    {
185
6.05k
        payload.checkParsed();
186
6.05k
    }
187
6.05k
    catch (const resip::ParseException&)
188
6.05k
    {
189
0
    }
190
6.05k
}
191
192
static void fuzzMessageWaitingContents(const resip::HeaderFieldValue& hfv)
193
6.05k
{
194
6.05k
    static const resip::Mime type("application", "simple-message-summary");
195
6.05k
    resip::MessageWaitingContents payload(hfv, type);
196
6.05k
    try
197
6.05k
    {
198
6.05k
        payload.checkParsed();
199
6.05k
    }
200
6.05k
    catch (const resip::ParseException&)
201
6.05k
    {
202
6.05k
    }
203
6.05k
}
204
205
static void fuzzMime(const resip::HeaderFieldValue& hfv)
206
6.05k
{
207
6.05k
    resip::Mime payload(hfv, resip::Headers::UNKNOWN);
208
6.05k
    try
209
6.05k
    {
210
6.05k
        payload.checkParsed();
211
6.05k
    }
212
6.05k
    catch (const resip::ParseException&)
213
6.05k
    {
214
5.29k
    }
215
6.05k
}
216
217
static void fuzzMultipartMixedContents(const resip::HeaderFieldValue& hfv)
218
6.05k
{
219
6.05k
    static const resip::Mime type("multipart", "mixed");
220
6.05k
    resip::MultipartMixedContents payload(hfv, type);
221
6.05k
    try
222
6.05k
    {
223
6.05k
        payload.checkParsed();
224
6.05k
    }
225
6.05k
    catch (const resip::ParseException&)
226
6.05k
    {
227
6.05k
    }
228
6.05k
}
229
230
static void fuzzNameAddr(const resip::Data& buffer)
231
6.05k
{
232
6.05k
  try
233
6.05k
  {
234
6.05k
    resip::NameAddr illegal(buffer);
235
6.05k
  }
236
6.05k
  catch (const resip::ParseException&)
237
6.05k
  {
238
3.27k
  }
239
6.05k
}
240
241
static void fuzzOctetContents(const resip::HeaderFieldValue& hfv)
242
6.05k
{
243
6.05k
    static const resip::Mime type("application", "octet-stream");
244
6.05k
    resip::OctetContents payload(hfv, type);
245
6.05k
    try
246
6.05k
    {
247
6.05k
        payload.checkParsed();
248
6.05k
    }
249
6.05k
    catch (const resip::ParseException&)
250
6.05k
    {
251
0
    }
252
6.05k
}
253
254
static void fuzzPkcs7Contents(const resip::HeaderFieldValue& hfv)
255
6.05k
{
256
6.05k
    static const resip::Mime type("application", "pkcs7-mime");
257
6.05k
    resip::Pkcs7Contents payload(hfv, type);
258
6.05k
    try
259
6.05k
    {
260
6.05k
        payload.checkParsed();
261
6.05k
    }
262
6.05k
    catch (const resip::ParseException&)
263
6.05k
    {
264
0
    }
265
6.05k
}
266
267
static void fuzzPkcs8Contents(const resip::HeaderFieldValue& hfv)
268
6.05k
{
269
6.05k
    static const resip::Mime type("application", "pkcs8");
270
6.05k
    resip::Pkcs8Contents payload(hfv, type);
271
6.05k
    try
272
6.05k
    {
273
6.05k
        payload.checkParsed();
274
6.05k
    }
275
6.05k
    catch (const resip::ParseException&)
276
6.05k
    {
277
0
    }
278
6.05k
}
279
280
static void fuzzPlainContents(const resip::HeaderFieldValue& hfv)
281
6.05k
{
282
6.05k
    static const resip::Mime type("text", "plain");
283
6.05k
    resip::PlainContents payload(hfv, type);
284
6.05k
    try
285
6.05k
    {
286
6.05k
        payload.checkParsed();
287
6.05k
    }
288
6.05k
    catch (const resip::ParseException&)
289
6.05k
    {
290
0
    }
291
6.05k
}
292
293
static void fuzzPrivacyCategory(const resip::HeaderFieldValue& hfv)
294
6.05k
{
295
6.05k
    resip::PrivacyCategory payload(hfv, resip::Headers::UNKNOWN);
296
6.05k
    try
297
6.05k
    {
298
6.05k
        payload.checkParsed();
299
6.05k
    }
300
6.05k
    catch (const resip::ParseException&)
301
6.05k
    {
302
3.37k
    }
303
6.05k
}
304
305
static void fuzzRAckCategory(const resip::HeaderFieldValue& hfv)
306
6.05k
{
307
6.05k
    resip::RAckCategory payload(hfv, resip::Headers::UNKNOWN);
308
6.05k
    try
309
6.05k
    {
310
6.05k
        payload.checkParsed();
311
6.05k
    }
312
6.05k
    catch (const resip::ParseException&)
313
6.05k
    {
314
6.03k
    }
315
6.05k
}
316
317
static void fuzzRequestLine(const resip::HeaderFieldValue& hfv)
318
6.05k
{
319
6.05k
    resip::RequestLine payload(hfv);
320
6.05k
    try
321
6.05k
    {
322
6.05k
        payload.checkParsed();
323
6.05k
    }
324
6.05k
    catch (const resip::ParseException&)
325
6.05k
    {
326
5.56k
    }
327
6.05k
}
328
329
static void fuzzRlmi(const resip::HeaderFieldValue& hfv)
330
6.05k
{
331
6.05k
    static const resip::Mime type("application", "rlmi+xml");
332
6.05k
    resip::Rlmi payload(hfv, type);
333
6.05k
    try
334
6.05k
    {
335
6.05k
        payload.checkParsed();
336
6.05k
    }
337
6.05k
    catch (const resip::ParseException&)
338
6.05k
    {
339
0
    }
340
6.05k
}
341
342
static void fuzzSdp(const resip::HeaderFieldValue& hfv)
343
6.05k
{
344
6.05k
  static const resip::Mime type("application", "sdp");
345
6.05k
  resip::SdpContents sdp(hfv, type);
346
6.05k
  try
347
6.05k
  {
348
6.05k
    sdp.checkParsed();
349
6.05k
  }
350
6.05k
  catch (const resip::ParseException&)
351
6.05k
  {
352
5.51k
  }
353
6.05k
}
354
355
static void fuzzSip(const resip::Data& buffer)
356
6.05k
{
357
6.05k
  try
358
6.05k
  {
359
6.05k
    std::unique_ptr<resip::SipMessage> msg(resip::TestSupport::makeMessage(buffer));
360
6.05k
  }
361
6.05k
  catch (const resip::ParseException&)
362
6.05k
  {
363
0
  }
364
6.05k
}
365
366
/*
367
368
TODO: add fuzzing for those classes
369
370
resip/stack/SipFrag.cxx:SipFrag::parse(ParseBuffer& pb)
371
resip/stack/StatusLine.cxx:StatusLine::parse(ParseBuffer& pb)
372
resip/stack/StringCategory.cxx:StringCategory::parse(ParseBuffer& pb)
373
resip/stack/Token.cxx:Token::parse(ParseBuffer& pb)
374
resip/stack/TokenOrQuotedStringCategory.cxx:TokenOrQuotedStringCategory::parse(ParseBuffer& pb)
375
resip/stack/UInt32Category.cxx:UInt32Category::parse(ParseBuffer& pb)
376
resip/stack/Via.cxx:Via::parse(ParseBuffer& pb)
377
resip/stack/WarningCategory.cxx:WarningCategory::parse(ParseBuffer& pb)
378
resip/stack/X509Contents.cxx:X509Contents::parse(ParseBuffer& pb)
379
380
*/
381
382
static void fuzzUri(const resip::HeaderFieldValue& hfv)
383
6.05k
{
384
6.05k
  resip::Uri uri(hfv, resip::Headers::UNKNOWN);
385
6.05k
  try
386
6.05k
  {
387
6.05k
    uri.embedded();
388
6.05k
  }
389
6.05k
  catch (const resip::ParseException&)
390
6.05k
  {
391
3.17k
  }
392
6.05k
}
393
394
2
extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) {
395
2
  resip::Log::initialize(resip::Log::Cout, resip::Log::None, *argv[0]);
396
2
  return 0;
397
2
}
398
399
// Entrypoint for Clang's libfuzzer
400
extern "C" int LLVMFuzzerTestOneInput(const unsigned char *data,
401
6.05k
                                      unsigned long size) {
402
403
6.05k
  const resip::Data buffer(resip::Data::Share, reinterpret_cast<const char*>(data), size);
404
6.05k
  const resip::HeaderFieldValue hfv(reinterpret_cast<const char*>(data), size);
405
406
6.05k
  fuzzAuth(hfv);
407
6.05k
  fuzzCSeqCategory(hfv);
408
6.05k
  fuzzCallId(hfv);
409
6.05k
  fuzzCpimContents(hfv);
410
6.05k
  fuzzDtmfPayloadContents(hfv);
411
6.05k
  fuzzDateCategory(hfv);
412
6.05k
  fuzzExpiresCategory(hfv);
413
6.05k
  fuzzGenericUri(hfv);
414
6.05k
  fuzzIntegerCategory(hfv);
415
6.05k
  fuzzInvalidContents(hfv);
416
6.05k
  fuzzMessageWaitingContents(hfv);
417
6.05k
  fuzzMime(hfv);
418
6.05k
  fuzzMultipartMixedContents(hfv);
419
6.05k
  fuzzNameAddr(buffer);
420
6.05k
  fuzzOctetContents(hfv);
421
422
6.05k
  fuzzPkcs7Contents(hfv);
423
6.05k
  fuzzPkcs8Contents(hfv);
424
6.05k
  fuzzPlainContents(hfv);
425
6.05k
  fuzzPrivacyCategory(hfv);
426
6.05k
  fuzzRAckCategory(hfv);
427
6.05k
  fuzzRequestLine(hfv);
428
6.05k
  fuzzRlmi(hfv);
429
6.05k
  fuzzSdp(hfv);
430
6.05k
  fuzzSip(buffer);
431
6.05k
  fuzzUri(hfv);
432
433
  // leaks or hogs memory
434
  //fuzzDialogInfoContents(hfv);
435
  //fuzzGenericPidfContents(hfv);
436
437
6.05k
  return 0;
438
6.05k
}
439
440
/* ====================================================================
441
 * The Vovida Software License, Version 1.0 
442
 * 
443
 * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
444
 * 
445
 * Redistribution and use in source and binary forms, with or without
446
 * modification, are permitted provided that the following conditions
447
 * are met:
448
 * 
449
 * 1. Redistributions of source code must retain the above copyright
450
 *    notice, this list of conditions and the following disclaimer.
451
 * 
452
 * 2. Redistributions in binary form must reproduce the above copyright
453
 *    notice, this list of conditions and the following disclaimer in
454
 *    the documentation and/or other materials provided with the
455
 *    distribution.
456
 * 
457
 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
458
 *    and "Vovida Open Communication Application Library (VOCAL)" must
459
 *    not be used to endorse or promote products derived from this
460
 *    software without prior written permission. For written
461
 *    permission, please contact vocal@vovida.org.
462
 *
463
 * 4. Products derived from this software may not be called "VOCAL", nor
464
 *    may "VOCAL" appear in their name, without prior written
465
 *    permission of Vovida Networks, Inc.
466
 * 
467
 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
468
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
469
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
470
 * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
471
 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
472
 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
473
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
474
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
475
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
476
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
477
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
478
 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
479
 * DAMAGE.
480
 * 
481
 * ====================================================================
482
 * 
483
 * This software consists of voluntary contributions made by Vovida
484
 * Networks, Inc. and many individuals on behalf of Vovida Networks,
485
 * Inc.  For more information on Vovida Networks, Inc., please see
486
 * <http://www.vovida.org/>.
487
 *
488
 */