Coverage Report

Created: 2018-08-29 13:53

/src/openssl/crypto/err/err_prn.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the OpenSSL license (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 <stdio.h>
11
#include "internal/cryptlib.h"
12
#include <openssl/crypto.h>
13
#include <openssl/buffer.h>
14
#include <openssl/err.h>
15
16
void ERR_print_errors_cb(int (*cb) (const char *str, size_t len, void *u),
17
                         void *u)
18
0
{
19
0
    unsigned long l;
20
0
    char buf[256];
21
0
    char buf2[4096];
22
0
    const char *file, *data;
23
0
    int line, flags;
24
0
    /*
25
0
     * We don't know what kind of thing CRYPTO_THREAD_ID is. Here is our best
26
0
     * attempt to convert it into something we can print.
27
0
     */
28
0
    union {
29
0
        CRYPTO_THREAD_ID tid;
30
0
        unsigned long ltid;
31
0
    } tid;
32
0
33
0
    tid.ltid = 0;
34
0
    tid.tid = CRYPTO_THREAD_get_current_id();
35
0
36
0
    while ((l = ERR_get_error_line_data(&file, &line, &data, &flags)) != 0) {
37
0
        ERR_error_string_n(l, buf, sizeof(buf));
38
0
        BIO_snprintf(buf2, sizeof(buf2), "%lu:%s:%s:%d:%s\n", tid.ltid, buf,
39
0
                     file, line, (flags & ERR_TXT_STRING) ? data : "");
40
0
        if (cb(buf2, strlen(buf2), u) <= 0)
41
0
            break;              /* abort outputting the error report */
42
0
    }
43
0
}
44
45
static int print_bio(const char *str, size_t len, void *bp)
46
0
{
47
0
    return BIO_write((BIO *)bp, str, len);
48
0
}
49
50
void ERR_print_errors(BIO *bp)
51
0
{
52
0
    ERR_print_errors_cb(print_bio, bp);
53
0
}
54
55
#ifndef OPENSSL_NO_STDIO
56
void ERR_print_errors_fp(FILE *fp)
57
0
{
58
0
    BIO *bio = BIO_new_fp(fp, BIO_NOCLOSE);
59
0
    if (bio == NULL)
60
0
        return;
61
0
62
0
    ERR_print_errors_cb(print_bio, bio);
63
0
    BIO_free(bio);
64
0
}
65
#endif