/src/open5gs/tests/fuzzing/nas-message-fuzz.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (C) 2019-2023 by Sukchan Lee <acetcom@gmail.com> |
3 | | * |
4 | | * This file is part of Open5GS. |
5 | | * |
6 | | * This program is free software: you can redistribute it and/or modify |
7 | | * it under the terms of the GNU Affero General Public License as published by |
8 | | * the Free Software Foundation, either version 3 of the License, or |
9 | | * (at your option) any later version. |
10 | | * |
11 | | * This program is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | * GNU General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU General Public License |
17 | | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
18 | | */ |
19 | | |
20 | | #include <stdio.h> |
21 | | #include <stdint.h> |
22 | | |
23 | | #include "fuzzing.h" |
24 | | #include "ogs-nas-eps.h" |
25 | | |
26 | 7.17k | #define kMinInputLength 5 |
27 | 3.58k | #define kMaxInputLength 1024 |
28 | | |
29 | | extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) |
30 | 3.58k | { /* open5gs/tests/unit/nas-message-test.c */ |
31 | | |
32 | 3.58k | if (Size < kMinInputLength || Size > kMaxInputLength) { |
33 | 26 | return 1; |
34 | 26 | } |
35 | | |
36 | 3.56k | if (!initialized) { |
37 | 1 | initialize(); |
38 | 1 | ogs_log_install_domain(&__ogs_nas_domain, "nas", OGS_LOG_NONE); |
39 | 1 | } |
40 | | |
41 | 3.56k | int result; |
42 | 3.56k | ogs_pkbuf_t *pkbuf; |
43 | 3.56k | ogs_nas_eps_message_t message; |
44 | | |
45 | 3.56k | pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); |
46 | 3.56k | if (pkbuf == NULL) { |
47 | 0 | return 1; |
48 | 0 | } |
49 | | |
50 | 3.56k | ogs_pkbuf_put_data(pkbuf, Data, Size); |
51 | | |
52 | 3.56k | result = ogs_nas_emm_decode(&message, pkbuf); |
53 | | |
54 | 3.56k | ogs_pkbuf_free(pkbuf); |
55 | | |
56 | 3.56k | return result; |
57 | 3.56k | } |