]>
git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/err/err_blocks.c
2 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
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
10 #define OSSL_FORCE_ERR_STATE
13 #include <openssl/err.h>
14 #include "err_local.h"
20 es
= ossl_err_get_state_int();
26 err_clear(es
, es
->top
, 0);
29 void ERR_set_debug(const char *file
, int line
, const char *func
)
33 es
= ossl_err_get_state_int();
37 err_set_debug(es
, es
->top
, file
, line
, func
);
40 void ERR_set_error(int lib
, int reason
, const char *fmt
, ...)
45 ERR_vset_error(lib
, reason
, fmt
, args
);
49 void ERR_vset_error(int lib
, int reason
, const char *fmt
, va_list args
)
54 unsigned long flags
= 0;
57 es
= ossl_err_get_state_int();
66 buf
= es
->err_data
[i
];
67 buf_size
= es
->err_data_size
[i
];
70 * To protect the string we just grabbed from tampering by other
71 * functions we may call, or to protect them from freeing a pointer
72 * that may no longer be valid at that point, we clear away the
73 * data pointer and the flags. We will set them again at the end
76 es
->err_data
[i
] = NULL
;
77 es
->err_data_flags
[i
] = 0;
80 * Try to maximize the space available. If that fails, we use what
83 if (buf_size
< ERR_MAX_DATA_SIZE
84 && (rbuf
= OPENSSL_realloc(buf
, ERR_MAX_DATA_SIZE
)) != NULL
) {
86 buf_size
= ERR_MAX_DATA_SIZE
;
90 printed_len
= BIO_vsnprintf(buf
, buf_size
, fmt
, args
);
95 buf
[printed_len
] = '\0';
98 * Try to reduce the size, but only if we maximized above. If that
99 * fails, we keep what we have.
100 * (According to documentation, realloc leaves the old buffer untouched
103 if ((rbuf
= OPENSSL_realloc(buf
, printed_len
+ 1)) != NULL
) {
105 buf_size
= printed_len
+ 1;
106 buf
[printed_len
] = '\0';
110 flags
= ERR_TXT_MALLOCED
| ERR_TXT_STRING
;
113 err_clear_data(es
, es
->top
, 0);
114 err_set_error(es
, es
->top
, lib
, reason
);
116 err_set_data(es
, es
->top
, buf
, buf_size
, flags
);