Coverage Report

Created: 2026-07-15 06:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libssh/tests/fuzz/ssh_privkey_fuzzer.c
Line
Count
Source
1
/*
2
 * Copyright 2023 Jakub Jelen <jjelen@redhat.com>
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#include "config.h"
18
19
#include <assert.h>
20
#include <stdio.h>
21
#include <stdlib.h>
22
#include <string.h>
23
24
#define LIBSSH_STATIC 1
25
#include "libssh/libssh.h"
26
#include "libssh/priv.h"
27
28
#include "nallocinc.c"
29
30
static void _fuzz_finalize(void)
31
4
{
32
4
    ssh_finalize();
33
4
}
34
35
int LLVMFuzzerInitialize(int *argc, char ***argv)
36
38
{
37
38
    (void)argc;
38
39
38
    nalloc_init(*argv[0]);
40
41
38
    ssh_init();
42
43
38
    atexit(_fuzz_finalize);
44
45
38
    return 0;
46
38
}
47
48
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
49
4.81k
{
50
4.81k
    ssh_key pkey = NULL;
51
4.81k
    uint8_t *input = NULL;
52
4.81k
    int rc;
53
54
4.81k
    assert(nalloc_start(data, size) > 0);
55
56
4.81k
    input = bin_to_base64(data, size);
57
4.81k
    if (input == NULL) {
58
421
        goto out;
59
421
    }
60
61
4.39k
    rc = ssh_pki_import_privkey_base64((char *)input, NULL, NULL, NULL, &pkey);
62
4.39k
    free(input);
63
4.39k
    if (rc != SSH_OK) {
64
4.39k
        goto out;
65
4.39k
    }
66
0
    ssh_key_free(pkey);
67
68
4.81k
out:
69
4.81k
    nalloc_end();
70
4.81k
    return 0;
71
0
}
72