Coverage Report

Created: 2026-06-30 06:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/open5gs/lib/asn1c/util/message.h
Line
Count
Source
1
/*
2
 * Copyright (C) 2019-2026 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
#ifndef OGS_ASN_MESSAGE_H
21
#define OGS_ASN_MESSAGE_H
22
23
#include "ogs-core.h"
24
25
#include "asn_internal.h"
26
#include "constr_TYPE.h"
27
#include "asn_SEQUENCE_OF.h"
28
29
/*
30
 * Access generated SEQUENCE OF/SET OF values that are represented as
31
 * pointers by newer asn1c output. Keep the asn_anonymous_sequence_ cast in
32
 * one place instead of spreading it across protocol code.
33
 *
34
 * These helpers are only for ASN.1 list wrappers whose first member is
35
 * compatible with asn_anonymous_sequence_. Do not use them for arbitrary
36
 * ASN.1 SEQUENCE values.
37
 */
38
static inline int ogs_asn_list_count(const void *list)
39
0
{
40
0
    const asn_anonymous_sequence_ *sequence = NULL;
41
0
42
0
    ogs_assert(list);
43
0
44
0
    sequence = (const asn_anonymous_sequence_ *)list;
45
0
46
0
    return sequence->count;
47
0
}
Unexecuted instantiation: ngap-message-fuzz.c:ogs_asn_list_count
Unexecuted instantiation: message.c:ogs_asn_list_count
Unexecuted instantiation: s1ap-message-fuzz.c:ogs_asn_list_count
48
49
static inline void *ogs_asn_list_get(const void *list, int index)
50
0
{
51
0
    const asn_anonymous_sequence_ *sequence = NULL;
52
0
53
0
    ogs_assert(list);
54
0
55
0
    sequence = (const asn_anonymous_sequence_ *)list;
56
0
57
0
    ogs_assert(index >= 0);
58
0
    ogs_assert(index < sequence->count);
59
0
    ogs_assert(sequence->array);
60
0
61
0
    return sequence->array[index];
62
0
}
Unexecuted instantiation: ngap-message-fuzz.c:ogs_asn_list_get
Unexecuted instantiation: message.c:ogs_asn_list_get
Unexecuted instantiation: s1ap-message-fuzz.c:ogs_asn_list_get
63
64
#define OGS_ASN_LIST_COUNT(__list) \
65
    ogs_asn_list_count(__list)
66
#define OGS_ASN_LIST_GET(__list, __index) \
67
    ogs_asn_list_get(__list, __index)
68
69
#ifdef __cplusplus
70
extern "C" {
71
#endif
72
73
/*
74
 * Allocate an ASN.1 constructed value from a descriptor when the concrete
75
 * C pointer type is not available at the call site.
76
 *
77
 * Prefer CALLOC(1, sizeof(*ptr)) whenever the destination pointer type is
78
 * known. This helper is mainly used by ogs_asn_calloc_protocol_ies(),
79
 * where only the generated descriptor is available.
80
 */
81
void *ogs_asn_calloc_constructed(const asn_TYPE_descriptor_t *td);
82
83
/*
84
 * Allocate protocolIEs from an ASN.1 procedure message descriptor.
85
 * The generated procedure SEQUENCE is expected to have protocolIEs
86
 * as member 0. Assert the member name here so callers do not silently
87
 * allocate the wrong member if generated layouts change.
88
 */
89
void *ogs_asn_calloc_protocol_ies(const asn_TYPE_descriptor_t *parent_td);
90
91
ogs_pkbuf_t *ogs_asn_encode(const asn_TYPE_descriptor_t *td, void *sptr);
92
int ogs_asn_decode(const asn_TYPE_descriptor_t *td,
93
        void *struct_ptr, size_t struct_size, ogs_pkbuf_t *pkbuf);
94
void ogs_asn_free(const asn_TYPE_descriptor_t *td, void *sptr);
95
96
#ifdef __cplusplus
97
}
98
#endif
99
100
#endif
101