Debian Codegraph @

Xpjproject/tests/fuzz/fuzz-dns-records.c

raw symbols SCIP
1 /*
2 * Copyright (C) 2026 Teluu Inc. (http://www.teluu.com)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 #include <stdio.h>
19 #include <stdint.h>
20 #include <stdlib.h>
21
22 #include <pjlib.h>
23 #include <pjlib-util/dns.h>
24 #include <pjlib-util/resolver.h>
25
26 #define POOL_SIZE 4000
27
28 /* Global state for one-time initialization */
29 static pj_caching_pool caching_pool;
30 static pj_pool_factory *mem;
31
32 extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
33 {
34 static int initialized = 0;
35 pj_pool_t *pool;
36 pj_status_t status;
37 pj_dns_parsed_packet *dns;
38
39 /* One-time initialization */
40 if (!initialized) {
41 pj_init();
42 pj_caching_pool_init(&caching_pool, &pj_pool_factory_default_policy, 0);
43 pj_log_set_level(0);
44 mem = &caching_pool.factory;
45 initialized = 1;
46 }
47
48 /* Skip tiny inputs */
49 if (Size < 12)
50 return 0;
51
52 /* Create pool for this iteration */
53 pool = pj_pool_create(mem, "dns", POOL_SIZE, POOL_SIZE, NULL);
54 if (!pool)
55 return 0;
56
57 /* Test DNS packet parsing */
58 status = pj_dns_parse_packet(pool, Data, (unsigned)Size, &dns);
59
60 if (status == PJ_SUCCESS && dns && dns->hdr.anscount > 0) {
61 /* Test A record parsing */
62 pj_dns_a_record a_rec;
63 pj_dns_parse_a_response(dns, &a_rec);
64
65 /* Test addr record parsing */
66 pj_dns_addr_record addr_rec;
67 pj_dns_parse_addr_response(dns, &addr_rec);
68 }
69
70 /* Release pool */
71 pj_pool_release(pool);
72
73 return 0;
74 }