Coverage Report

Created: 2026-03-31 07:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/pacemaker/lib/common/fuzzers/iso8601_fuzzer.c
Line
Count
Source
1
/*
2
 * Copyright 2024-2025 the Pacemaker project contributors
3
 *
4
 * The version control history for this file may have further details.
5
 *
6
 * This source code is licensed under the GNU Lesser General Public License
7
 * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8
 */
9
10
#include <stdint.h>
11
#include <stdlib.h>
12
#include <stdio.h>
13
#include <time.h>                   // struct timespec
14
15
#include <qb/qbutil.h>              // qb_util_timespec_from_epoch_get()
16
17
#include <crm/common/util.h>
18
#include <crm/common/internal.h>
19
20
int
21
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
22
3.94k
{
23
3.94k
    char *ns = NULL;
24
3.94k
    crm_time_period_t *period = NULL;
25
26
3.94k
    struct timespec tv = { 0, };
27
3.94k
    crm_time_t *now = NULL;
28
3.94k
    char *result = NULL;
29
30
    // Ensure we have enough data.
31
3.94k
    if (size < 10) {
32
16
        return -1; // Do not add input to testing corpus
33
16
    }
34
3.92k
    ns = pcmk__assert_alloc(size + 1, sizeof(char));
35
3.92k
    memcpy(ns, data, size);
36
37
3.92k
    period = crm_time_parse_period(ns);
38
3.92k
    crm_time_free_period(period);
39
40
3.92k
    qb_util_timespec_from_epoch_get(&tv);
41
3.92k
    now = pcmk__copy_timet(tv.tv_sec);
42
3.92k
    result = pcmk__time_format_hr(ns, now,
43
3.92k
                                  (int) (tv.tv_nsec / QB_TIME_NS_IN_USEC));
44
3.92k
    crm_time_free(now);
45
3.92k
    free(result);
46
47
3.92k
    free(ns);
48
3.92k
    return 0;
49
3.94k
}