Coverage Report

Created: 2024-11-21 07:03

/src/openssl/crypto/comp_methods.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2024 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License 2.0 (the "License").  You may not use
5
 * this file except in compliance with the License.  You can obtain a copy
6
 * in the file LICENSE in the source distribution or at
7
 * https://www.openssl.org/source/license.html
8
 */
9
10
#include <openssl/crypto.h>
11
#include <openssl/comp.h>
12
#include <openssl/obj_mac.h>
13
14
#include "internal/cryptlib.h"
15
#include "internal/comp.h"
16
17
#define SSL_COMP_NULL_IDX       0
18
0
#define SSL_COMP_ZLIB_IDX       1
19
#define SSL_COMP_NUM_IDX        2
20
21
#ifndef OPENSSL_NO_COMP
22
static int sk_comp_cmp(const SSL_COMP *const *a, const SSL_COMP *const *b)
23
0
{
24
0
    return ((*a)->id - (*b)->id);
25
0
}
26
#endif
27
28
STACK_OF(SSL_COMP) *ossl_load_builtin_compressions(void)
29
4
{
30
4
    STACK_OF(SSL_COMP) *comp_methods = NULL;
31
4
#ifndef OPENSSL_NO_COMP
32
4
    SSL_COMP *comp = NULL;
33
4
    COMP_METHOD *method = COMP_zlib();
34
35
4
    comp_methods = sk_SSL_COMP_new(sk_comp_cmp);
36
37
4
    if (COMP_get_type(method) != NID_undef && comp_methods != NULL) {
38
0
        comp = OPENSSL_malloc(sizeof(*comp));
39
0
        if (comp != NULL) {
40
0
            comp->method = method;
41
0
            comp->id = SSL_COMP_ZLIB_IDX;
42
0
            comp->name = COMP_get_name(method);
43
0
            if (!sk_SSL_COMP_push(comp_methods, comp))
44
0
                OPENSSL_free(comp);
45
0
        }
46
0
    }
47
4
#endif
48
4
    return comp_methods;
49
4
}
50
51
static void cmeth_free(SSL_COMP *cm)
52
0
{
53
0
    OPENSSL_free(cm);
54
0
}
55
56
void ossl_free_compression_methods_int(STACK_OF(SSL_COMP) *methods)
57
4
{
58
4
    sk_SSL_COMP_pop_free(methods, cmeth_free);
59
4
}