]>
Commit | Line | Data |
---|---|---|
aa6bb135 | 1 | /* |
2d905f67 | 2 | * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved. |
d02b48c6 | 3 | * |
4ad239b8 | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
aa6bb135 RS |
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 | |
d02b48c6 RE |
8 | */ |
9 | ||
14e275e8 RL |
10 | /* TODO: When ERR_STATE becomes opaque, this musts be removed */ |
11 | #define OSSL_FORCE_ERR_STATE | |
12 | ||
d02b48c6 | 13 | #include <stdio.h> |
b39fc560 | 14 | #include "internal/cryptlib.h" |
ec577822 | 15 | #include <openssl/crypto.h> |
ec577822 BM |
16 | #include <openssl/buffer.h> |
17 | #include <openssl/err.h> | |
b579014d | 18 | #include "err_locl.h" |
d02b48c6 | 19 | |
0f113f3e MC |
20 | void ERR_print_errors_cb(int (*cb) (const char *str, size_t len, void *u), |
21 | void *u) | |
22 | { | |
2d905f67 | 23 | CRYPTO_THREAD_ID tid = CRYPTO_THREAD_get_current_id(); |
0f113f3e | 24 | unsigned long l; |
b579014d RL |
25 | char buf[4096], *hex; |
26 | const char *lib, *reason; | |
27 | const char *file, *data, *func; | |
0f113f3e | 28 | int line, flags; |
d02b48c6 | 29 | |
b579014d RL |
30 | while ((l = ERR_get_error_all(&file, &line, &func, &data, &flags)) != 0) { |
31 | lib = ERR_lib_error_string(l); | |
32 | reason = ERR_reason_error_string(l); | |
33 | if (func == NULL) | |
34 | func = "unknown function"; | |
35 | if ((flags & ERR_TXT_STRING) == 0) | |
36 | data = ""; | |
2d905f67 | 37 | hex = OPENSSL_buf2hexstr((const unsigned char *)&tid, sizeof(tid)); |
b579014d RL |
38 | BIO_snprintf(buf, sizeof(buf), "%s:error:%s:%s:%s:%s:%d:%s\n", |
39 | hex, lib, func, reason, file, line, data); | |
2d905f67 | 40 | OPENSSL_free(hex); |
b579014d | 41 | if (cb(buf, strlen(buf), u) <= 0) |
0f113f3e MC |
42 | break; /* abort outputting the error report */ |
43 | } | |
44 | } | |
8ada6e77 | 45 | |
6a184a60 | 46 | static int print_bio(const char *str, size_t len, void *bp) |
0f113f3e MC |
47 | { |
48 | return BIO_write((BIO *)bp, str, len); | |
49 | } | |
d02b48c6 | 50 | |
0f113f3e MC |
51 | void ERR_print_errors(BIO *bp) |
52 | { | |
53 | ERR_print_errors_cb(print_bio, bp); | |
54 | } | |
1a50b813 F |
55 | |
56 | #ifndef OPENSSL_NO_STDIO | |
57 | void ERR_print_errors_fp(FILE *fp) | |
58 | { | |
59 | BIO *bio = BIO_new_fp(fp, BIO_NOCLOSE); | |
60 | if (bio == NULL) | |
61 | return; | |
62 | ||
63 | ERR_print_errors_cb(print_bio, bio); | |
64 | BIO_free(bio); | |
65 | } | |
66 | #endif |