Coverage Report

Created: 2026-07-14 06:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/open5gs/lib/asn1c/common/OBJECT_IDENTIFIER_rfill.c
Line
Count
Source
1
/*
2
 * Copyright (c) 2017 Lev Walkin <vlm@lionet.info>.
3
 * All rights reserved.
4
 * Redistribution and modifications are permitted subject to BSD license.
5
 */
6
#include <asn_internal.h>
7
#include <OBJECT_IDENTIFIER.h>
8
9
/*
10
 * Generate values from the list of interesting values, or just a random
11
 * value up to the upper limit.
12
 */
13
static asn_oid_arc_t
14
0
OBJECT_IDENTIFIER__biased_random_arc(asn_oid_arc_t upper_bound) {
15
0
    const asn_oid_arc_t values[] = {0, 1, 127, 128, 129, 254, 255, 256};
16
0
    size_t idx;
17
18
0
    switch(asn_random_between(0, 2)) {
19
0
    case 0:
20
0
        idx = asn_random_between(0, sizeof(values) / sizeof(values[0]) - 1);
21
0
        if(values[idx] < upper_bound) {
22
0
            return values[idx];
23
0
        }
24
        /* Fall through */
25
0
    case 1:
26
0
        return asn_random_between(0, upper_bound);
27
0
    case 2:
28
0
    default:
29
0
        return upper_bound;
30
0
    }
31
0
}
32
33
asn_random_fill_result_t
34
OBJECT_IDENTIFIER_random_fill(const asn_TYPE_descriptor_t *td, void **sptr,
35
                              const asn_encoding_constraints_t *constraints,
36
0
                              size_t max_length) {
37
0
    asn_random_fill_result_t result_ok = {ARFILL_OK, 1};
38
0
    asn_random_fill_result_t result_failed = {ARFILL_FAILED, 0};
39
0
    asn_random_fill_result_t result_skipped = {ARFILL_SKIPPED, 0};
40
0
    OBJECT_IDENTIFIER_t *st;
41
0
    asn_oid_arc_t arcs[5];
42
0
    size_t arcs_len = asn_random_between(2, 5);
43
0
    size_t i;
44
45
0
    (void)constraints;
46
47
0
    if(max_length < arcs_len) return result_skipped;
48
49
0
    if(*sptr) {
50
0
        st = *sptr;
51
0
    } else {
52
0
        st = CALLOC(1, sizeof(*st));
53
0
    }
54
55
0
    arcs[0] = asn_random_between(0, 2);
56
0
    arcs[1] = OBJECT_IDENTIFIER__biased_random_arc(
57
0
        arcs[0] <= 1 ? 39 : (ASN_OID_ARC_MAX - 80));
58
0
    for(i = 2; i < arcs_len; i++) {
59
0
        arcs[i] = OBJECT_IDENTIFIER__biased_random_arc(ASN_OID_ARC_MAX);
60
0
    }
61
62
0
    if(OBJECT_IDENTIFIER_set_arcs(st, arcs, arcs_len)) {
63
0
        if(st != *sptr) {
64
0
            ASN_STRUCT_FREE(*td, st);
65
0
        }
66
0
        return result_failed;
67
0
    }
68
69
0
    *sptr = st;
70
71
0
    result_ok.length = st->size;
72
0
    return result_ok;
73
0
}