Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 1 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 2 | * All rights reserved. |
| 3 | * |
| 4 | * This package is an SSL implementation written |
| 5 | * by Eric Young (eay@cryptsoft.com). |
| 6 | * The implementation was written so as to conform with Netscapes SSL. |
| 7 | * |
| 8 | * This library is free for commercial and non-commercial use as long as |
| 9 | * the following conditions are aheared to. The following conditions |
| 10 | * apply to all code found in this distribution, be it the RC4, RSA, |
| 11 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
| 12 | * included with this distribution is covered by the same copyright terms |
| 13 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
| 14 | * |
| 15 | * Copyright remains Eric Young's, and as such any Copyright notices in |
| 16 | * the code are not to be removed. |
| 17 | * If this package is used in a product, Eric Young should be given attribution |
| 18 | * as the author of the parts of the library used. |
| 19 | * This can be in the form of a textual message at program startup or |
| 20 | * in documentation (online or textual) provided with the package. |
| 21 | * |
| 22 | * Redistribution and use in source and binary forms, with or without |
| 23 | * modification, are permitted provided that the following conditions |
| 24 | * are met: |
| 25 | * 1. Redistributions of source code must retain the copyright |
| 26 | * notice, this list of conditions and the following disclaimer. |
| 27 | * 2. Redistributions in binary form must reproduce the above copyright |
| 28 | * notice, this list of conditions and the following disclaimer in the |
| 29 | * documentation and/or other materials provided with the distribution. |
| 30 | * 3. All advertising materials mentioning features or use of this software |
| 31 | * must display the following acknowledgement: |
| 32 | * "This product includes cryptographic software written by |
| 33 | * Eric Young (eay@cryptsoft.com)" |
| 34 | * The word 'cryptographic' can be left out if the rouines from the library |
| 35 | * being used are not cryptographic related :-). |
| 36 | * 4. If you include any Windows specific code (or a derivative thereof) from |
| 37 | * the apps directory (application code) you must include an acknowledgement: |
| 38 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
| 39 | * |
| 40 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
| 41 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 43 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 44 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 45 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 46 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 48 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 49 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 50 | * SUCH DAMAGE. |
| 51 | * |
| 52 | * The licence and distribution terms for any publically available version or |
| 53 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
| 54 | * copied and put under another distribution licence |
| 55 | * [including the GNU Public Licence.] |
| 56 | */ |
| 57 | /* ==================================================================== |
| 58 | * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved. |
| 59 | * |
| 60 | * Redistribution and use in source and binary forms, with or without |
| 61 | * modification, are permitted provided that the following conditions |
| 62 | * are met: |
| 63 | * |
| 64 | * 1. Redistributions of source code must retain the above copyright |
| 65 | * notice, this list of conditions and the following disclaimer. |
| 66 | * |
| 67 | * 2. Redistributions in binary form must reproduce the above copyright |
| 68 | * notice, this list of conditions and the following disclaimer in |
| 69 | * the documentation and/or other materials provided with the |
| 70 | * distribution. |
| 71 | * |
| 72 | * 3. All advertising materials mentioning features or use of this |
| 73 | * software must display the following acknowledgment: |
| 74 | * "This product includes software developed by the OpenSSL Project |
| 75 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" |
| 76 | * |
| 77 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to |
| 78 | * endorse or promote products derived from this software without |
| 79 | * prior written permission. For written permission, please contact |
| 80 | * openssl-core@openssl.org. |
| 81 | * |
| 82 | * 5. Products derived from this software may not be called "OpenSSL" |
| 83 | * nor may "OpenSSL" appear in their names without prior written |
| 84 | * permission of the OpenSSL Project. |
| 85 | * |
| 86 | * 6. Redistributions of any form whatsoever must retain the following |
| 87 | * acknowledgment: |
| 88 | * "This product includes software developed by the OpenSSL Project |
| 89 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" |
| 90 | * |
| 91 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY |
| 92 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 93 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 94 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR |
| 95 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 96 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 97 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 98 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 99 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 100 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 101 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 102 | * OF THE POSSIBILITY OF SUCH DAMAGE. |
| 103 | * ==================================================================== |
| 104 | * |
| 105 | * This product includes cryptographic software written by Eric Young |
| 106 | * (eay@cryptsoft.com). This product includes software written by Tim |
| 107 | * Hudson (tjh@cryptsoft.com). */ |
| 108 | |
| 109 | #ifndef OPENSSL_HEADER_ERR_H |
| 110 | #define OPENSSL_HEADER_ERR_H |
| 111 | |
Brian Smith | 83a8298 | 2015-04-09 16:21:10 -1000 | [diff] [blame] | 112 | #include <stdio.h> |
| 113 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 114 | #include <openssl/base.h> |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 115 | |
| 116 | #if defined(__cplusplus) |
| 117 | extern "C" { |
| 118 | #endif |
| 119 | |
| 120 | |
| 121 | /* Error queue handling functions. |
| 122 | * |
| 123 | * Errors in OpenSSL are generally signalled by the return value of a function. |
| 124 | * When a function fails it may add an entry to a per-thread error queue, |
| 125 | * which is managed by the functions in this header. |
| 126 | * |
| 127 | * Each error contains: |
| 128 | * 1) The library (i.e. ec, pem, rsa) which created it. |
David Benjamin | 3fc138e | 2015-10-28 18:03:21 -0400 | [diff] [blame] | 129 | * 2) The file and line number of the call that added the error. |
David Benjamin | 34248d4 | 2015-06-28 23:36:21 -0400 | [diff] [blame] | 130 | * 3) A pointer to some error specific data, which may be NULL. |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 131 | * |
David Benjamin | 34248d4 | 2015-06-28 23:36:21 -0400 | [diff] [blame] | 132 | * The library identifier and reason code are packed in a uint32_t and there |
| 133 | * exist various functions for unpacking it. |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 134 | * |
| 135 | * The typical behaviour is that an error will occur deep in a call queue and |
| 136 | * that code will push an error onto the error queue. As the error queue |
| 137 | * unwinds, other functions will push their own errors. Thus, the "least |
| 138 | * recent" error is the most specific and the other errors will provide a |
| 139 | * backtrace of sorts. */ |
| 140 | |
| 141 | |
| 142 | /* Startup and shutdown. */ |
| 143 | |
Matt Braithwaite | 9febf19 | 2015-04-30 13:04:06 -0700 | [diff] [blame] | 144 | /* ERR_load_BIO_strings does nothing. |
| 145 | * |
| 146 | * TODO(fork): remove. libjingle calls this. */ |
| 147 | OPENSSL_EXPORT void ERR_load_BIO_strings(void); |
| 148 | |
| 149 | /* ERR_load_ERR_strings does nothing. */ |
| 150 | OPENSSL_EXPORT void ERR_load_ERR_strings(void); |
| 151 | |
Adam Langley | 29b1867 | 2015-02-06 11:52:16 -0800 | [diff] [blame] | 152 | /* ERR_load_crypto_strings does nothing. */ |
David Benjamin | c44d2f4 | 2014-08-20 16:24:00 -0400 | [diff] [blame] | 153 | OPENSSL_EXPORT void ERR_load_crypto_strings(void); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 154 | |
Adam Langley | b9e77a0 | 2015-03-31 18:36:20 -0700 | [diff] [blame] | 155 | /* ERR_free_strings does nothing. */ |
David Benjamin | c44d2f4 | 2014-08-20 16:24:00 -0400 | [diff] [blame] | 156 | OPENSSL_EXPORT void ERR_free_strings(void); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 157 | |
| 158 | |
| 159 | /* Reading and formatting errors. */ |
| 160 | |
| 161 | /* ERR_get_error gets the packed error code for the least recent error and |
| 162 | * removes that error from the queue. If there are no errors in the queue then |
| 163 | * it returns zero. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 164 | OPENSSL_EXPORT uint32_t ERR_get_error(void); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 165 | |
| 166 | /* ERR_get_error_line acts like |ERR_get_error|, except that the file and line |
| 167 | * number of the call that added the error are also returned. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 168 | OPENSSL_EXPORT uint32_t ERR_get_error_line(const char **file, int *line); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 169 | |
| 170 | /* ERR_get_error_line_data acts like |ERR_get_error_line|, but also returns the |
| 171 | * error-specific data pointer and flags. The flags are a bitwise-OR of |
Adam Langley | 5f1374e | 2014-10-01 15:21:01 -0700 | [diff] [blame] | 172 | * |ERR_FLAG_*| values. The error-specific data is owned by the error queue |
| 173 | * and the pointer becomes invalid after the next call that affects the same |
| 174 | * thread's error queue. If |*flags| contains |ERR_FLAG_STRING| then |*data| is |
| 175 | * human-readable. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 176 | OPENSSL_EXPORT uint32_t ERR_get_error_line_data(const char **file, int *line, |
Adam Langley | 5f1374e | 2014-10-01 15:21:01 -0700 | [diff] [blame] | 177 | const char **data, int *flags); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 178 | |
| 179 | /* The "peek" functions act like the |ERR_get_error| functions, above, but they |
| 180 | * do not remove the error from the queue. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 181 | OPENSSL_EXPORT uint32_t ERR_peek_error(void); |
| 182 | OPENSSL_EXPORT uint32_t ERR_peek_error_line(const char **file, int *line); |
| 183 | OPENSSL_EXPORT uint32_t ERR_peek_error_line_data(const char **file, int *line, |
| 184 | const char **data, int *flags); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 185 | |
| 186 | /* The "peek last" functions act like the "peek" functions, above, except that |
| 187 | * they return the most recent error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 188 | OPENSSL_EXPORT uint32_t ERR_peek_last_error(void); |
| 189 | OPENSSL_EXPORT uint32_t ERR_peek_last_error_line(const char **file, int *line); |
David Benjamin | 5b082e8 | 2014-12-26 00:54:52 -0500 | [diff] [blame] | 190 | OPENSSL_EXPORT uint32_t ERR_peek_last_error_line_data(const char **file, |
| 191 | int *line, |
| 192 | const char **data, |
| 193 | int *flags); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 194 | |
| 195 | /* ERR_error_string generates a human-readable string representing |
| 196 | * |packed_error|, places it at |buf| (which must be at least |
| 197 | * ERR_ERROR_STRING_BUF_LEN bytes long) and returns |buf|. If |buf| is NULL, |
| 198 | * the error string is placed in a static buffer which is returned. (The static |
| 199 | * buffer may be overridden by concurrent calls in other threads so this form |
| 200 | * is deprecated.) |
| 201 | * |
| 202 | * The string will have the following format: |
| 203 | * |
David Benjamin | 34248d4 | 2015-06-28 23:36:21 -0400 | [diff] [blame] | 204 | * error:[error code]:[library name]:OPENSSL_internal:[reason string] |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 205 | * |
David Benjamin | 34248d4 | 2015-06-28 23:36:21 -0400 | [diff] [blame] | 206 | * error code is an 8 digit hexadecimal number; library name and reason string |
| 207 | * are ASCII text. |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 208 | * |
| 209 | * TODO(fork): remove in favour of |ERR_error_string_n|. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 210 | OPENSSL_EXPORT char *ERR_error_string(uint32_t packed_error, char *buf); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 211 | #define ERR_ERROR_STRING_BUF_LEN 256 |
| 212 | |
| 213 | /* ERR_error_string_n is a variant of |ERR_error_string| that writes at most |
| 214 | * len characters (including the terminating NUL) and truncates the string if |
| 215 | * necessary. If |len| is greater than zero then |buf| is always NUL |
| 216 | * terminated. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 217 | OPENSSL_EXPORT void ERR_error_string_n(uint32_t packed_error, char *buf, |
| 218 | size_t len); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 219 | |
| 220 | /* ERR_lib_error_string returns a string representation of the library that |
| 221 | * generated |packed_error|. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 222 | OPENSSL_EXPORT const char *ERR_lib_error_string(uint32_t packed_error); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 223 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 224 | /* ERR_reason_error_string returns a string representation of the reason for |
| 225 | * |packed_error|. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 226 | OPENSSL_EXPORT const char *ERR_reason_error_string(uint32_t packed_error); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 227 | |
| 228 | /* ERR_print_errors_callback_t is the type of a function used by |
| 229 | * |ERR_print_errors_cb|. It takes a pointer to a human readable string (and |
| 230 | * its length) that describes an entry in the error queue. The |ctx| argument |
| 231 | * is an opaque pointer given to |ERR_print_errors_cb|. |
| 232 | * |
| 233 | * It should return one on success or zero on error, which will stop the |
| 234 | * iteration over the error queue. */ |
| 235 | typedef int (*ERR_print_errors_callback_t)(const char *str, size_t len, |
| 236 | void *ctx); |
| 237 | |
| 238 | /* ERR_print_errors_cb calls |callback| with a string representation of each |
| 239 | * error in the current thread's error queue, from the least recent to the most |
| 240 | * recent error. |
| 241 | * |
| 242 | * The string will have the following format (which differs from |
| 243 | * |ERR_error_string|): |
| 244 | * |
David Benjamin | 3fc138e | 2015-10-28 18:03:21 -0400 | [diff] [blame] | 245 | * [thread id]:error:[error code]:[library name]:OPENSSL_internal: |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 246 | * [reason string]:[file]:[line number]:[optional string data] |
| 247 | * |
| 248 | * (All in one line.) |
| 249 | * |
| 250 | * The callback can return one to continue the iteration or zero to stop it. |
| 251 | * The |ctx| argument is an opaque value that is passed through to the |
| 252 | * callback. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 253 | OPENSSL_EXPORT void ERR_print_errors_cb(ERR_print_errors_callback_t callback, |
| 254 | void *ctx); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 255 | |
Brian Smith | f86c199 | 2015-04-14 06:45:04 -1000 | [diff] [blame] | 256 | /* ERR_print_errors_fp prints the current contents of the error stack to |file| |
Brian Smith | 83a8298 | 2015-04-09 16:21:10 -1000 | [diff] [blame] | 257 | * using human readable strings where possible. */ |
| 258 | OPENSSL_EXPORT void ERR_print_errors_fp(FILE *file); |
| 259 | |
David Benjamin | 2079ee7 | 2015-09-15 01:34:37 -0400 | [diff] [blame] | 260 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 261 | /* Clearing errors. */ |
| 262 | |
| 263 | /* ERR_clear_error clears the error queue for the current thread. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 264 | OPENSSL_EXPORT void ERR_clear_error(void); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 265 | |
Adam Langley | b9e77a0 | 2015-03-31 18:36:20 -0700 | [diff] [blame] | 266 | /* ERR_remove_thread_state clears the error queue for the current thread if |
Matt Braithwaite | 9b68e72 | 2015-05-06 13:57:29 -0700 | [diff] [blame] | 267 | * |tid| is NULL. Otherwise it calls |assert(0)|, because it's no longer |
| 268 | * possible to delete the error queue for other threads. |
Adam Langley | b9e77a0 | 2015-03-31 18:36:20 -0700 | [diff] [blame] | 269 | * |
| 270 | * Error queues are thread-local data and are deleted automatically. You do not |
Matt Braithwaite | 9b68e72 | 2015-05-06 13:57:29 -0700 | [diff] [blame] | 271 | * need to call this function. Use |ERR_clear_error|. */ |
Adam Langley | 03d31ed | 2014-08-05 16:54:47 -0700 | [diff] [blame] | 272 | OPENSSL_EXPORT void ERR_remove_thread_state(const CRYPTO_THREADID *tid); |
| 273 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 274 | |
Adam Langley | 4042667 | 2014-07-01 16:48:28 -0700 | [diff] [blame] | 275 | /* Custom errors. */ |
| 276 | |
| 277 | /* ERR_get_next_error_library returns a value suitable for passing as the |
| 278 | * |library| argument to |ERR_put_error|. This is intended for code that wishes |
| 279 | * to push its own, non-standard errors to the error queue. */ |
David Benjamin | c44d2f4 | 2014-08-20 16:24:00 -0400 | [diff] [blame] | 280 | OPENSSL_EXPORT int ERR_get_next_error_library(void); |
Adam Langley | 4042667 | 2014-07-01 16:48:28 -0700 | [diff] [blame] | 281 | |
| 282 | |
Matt Braithwaite | 9b68e72 | 2015-05-06 13:57:29 -0700 | [diff] [blame] | 283 | /* Deprecated functions. */ |
| 284 | |
Kenny Root | 3a9e1fb | 2015-06-10 14:52:40 -0700 | [diff] [blame] | 285 | /* ERR_remove_state calls |ERR_clear_error|. */ |
Matt Braithwaite | 9b68e72 | 2015-05-06 13:57:29 -0700 | [diff] [blame] | 286 | OPENSSL_EXPORT void ERR_remove_state(unsigned long pid); |
| 287 | |
David Benjamin | 34248d4 | 2015-06-28 23:36:21 -0400 | [diff] [blame] | 288 | /* ERR_func_error_string returns the string "OPENSSL_internal". */ |
| 289 | OPENSSL_EXPORT const char *ERR_func_error_string(uint32_t packed_error); |
| 290 | |
Matt Braithwaite | 9b68e72 | 2015-05-06 13:57:29 -0700 | [diff] [blame] | 291 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 292 | /* Private functions. */ |
| 293 | |
| 294 | /* ERR_clear_system_error clears the system's error value (i.e. errno). */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 295 | OPENSSL_EXPORT void ERR_clear_system_error(void); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 296 | |
| 297 | /* OPENSSL_PUT_ERROR is used by OpenSSL code to add an error to the error |
| 298 | * queue. */ |
David Benjamin | 3fc138e | 2015-10-28 18:03:21 -0400 | [diff] [blame] | 299 | #define OPENSSL_PUT_ERROR(library, reason) \ |
| 300 | ERR_put_error(ERR_LIB_##library, 0, reason, __FILE__, __LINE__) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 301 | |
| 302 | /* OPENSSL_PUT_SYSTEM_ERROR is used by OpenSSL code to add an error from the |
Adam Langley | 5f88999 | 2015-11-04 14:05:00 -0800 | [diff] [blame] | 303 | * operating system to the error queue. |
| 304 | * TODO(fork): include errno. */ |
David Benjamin | 3fc138e | 2015-10-28 18:03:21 -0400 | [diff] [blame] | 305 | #define OPENSSL_PUT_SYSTEM_ERROR() \ |
| 306 | ERR_put_error(ERR_LIB_SYS, 0, 0, __FILE__, __LINE__); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 307 | |
| 308 | /* ERR_put_error adds an error to the error queue, dropping the least recent |
| 309 | * error if neccessary for space reasons. */ |
David Benjamin | 3fc138e | 2015-10-28 18:03:21 -0400 | [diff] [blame] | 310 | OPENSSL_EXPORT void ERR_put_error(int library, int unused, int reason, |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 311 | const char *file, unsigned line); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 312 | |
| 313 | /* ERR_add_error_data takes a variable number (|count|) of const char* |
| 314 | * pointers, concatenates them and sets the result as the data on the most |
| 315 | * recent error. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 316 | OPENSSL_EXPORT void ERR_add_error_data(unsigned count, ...); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 317 | |
| 318 | /* ERR_add_error_dataf takes a printf-style format and arguments, and sets the |
| 319 | * result as the data on the most recent error. */ |
Brian Smith | 8d3c43e | 2016-01-17 10:14:08 -1000 | [diff] [blame] | 320 | OPENSSL_EXPORT void ERR_add_error_dataf(const char *format, ...) |
| 321 | OPENSSL_PRINTF_FORMAT_FUNC(1, 2); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 322 | |
| 323 | /* ERR_set_mark "marks" the most recent error for use with |ERR_pop_to_mark|. |
| 324 | * It returns one if an error was marked and zero if there are no errors. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 325 | OPENSSL_EXPORT int ERR_set_mark(void); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 326 | |
| 327 | /* ERR_pop_to_mark removes errors from the most recent to the least recent |
| 328 | * until (and not including) a "marked" error. It returns zero if no marked |
| 329 | * error was found (and thus all errors were removed) and one otherwise. Errors |
| 330 | * are marked using |ERR_set_mark|. */ |
Adam Langley | eb7d2ed | 2014-07-30 16:02:14 -0700 | [diff] [blame] | 331 | OPENSSL_EXPORT int ERR_pop_to_mark(void); |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 332 | |
| 333 | struct err_error_st { |
| 334 | /* file contains the filename where the error occured. */ |
| 335 | const char *file; |
| 336 | /* data contains optional data. It must be freed with |OPENSSL_free| if |
| 337 | * |flags&ERR_FLAG_MALLOCED|. */ |
| 338 | char *data; |
David Benjamin | 3fc138e | 2015-10-28 18:03:21 -0400 | [diff] [blame] | 339 | /* packed contains the error library and reason, as packed by ERR_PACK. */ |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 340 | uint32_t packed; |
| 341 | /* line contains the line number where the error occured. */ |
| 342 | uint16_t line; |
| 343 | /* flags contains a bitwise-OR of ERR_FLAG_* values. */ |
| 344 | uint8_t flags; |
| 345 | }; |
| 346 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 347 | /* ERR_FLAG_STRING means that the |data| member is a NUL-terminated string that |
| 348 | * can be printed. */ |
Adam Langley | 5f1374e | 2014-10-01 15:21:01 -0700 | [diff] [blame] | 349 | #define ERR_FLAG_STRING 1 |
Piotr Sikora | c3e4317 | 2014-07-14 20:31:27 -0700 | [diff] [blame] | 350 | /* ERR_TXT_STRING is provided for compatibility with code that assumes that |
| 351 | * it's using OpenSSL. */ |
| 352 | #define ERR_TXT_STRING ERR_FLAG_STRING |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 353 | |
| 354 | /* ERR_FLAG_PUBLIC_MASK is applied to the flags field before it is returned |
| 355 | * from functions like |ERR_get_error_line_data|. */ |
| 356 | #define ERR_FLAG_PUBLIC_MASK 0xf |
| 357 | |
| 358 | /* The following flag values are internal and are masked when flags are |
| 359 | * returned from functions like |ERR_get_error_line_data|. */ |
| 360 | |
Adam Langley | 5f1374e | 2014-10-01 15:21:01 -0700 | [diff] [blame] | 361 | /* ERR_FLAG_MALLOCED means the the |data| member must be freed when no longer |
| 362 | * needed. */ |
| 363 | #define ERR_FLAG_MALLOCED 16 |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 364 | /* ERR_FLAG_MARK is used to indicate a reversion point in the queue. See |
| 365 | * |ERR_pop_to_mark|. */ |
Adam Langley | 5f1374e | 2014-10-01 15:21:01 -0700 | [diff] [blame] | 366 | #define ERR_FLAG_MARK 32 |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 367 | |
| 368 | /* ERR_NUM_ERRORS is the limit of the number of errors in the queue. */ |
| 369 | #define ERR_NUM_ERRORS 16 |
| 370 | |
Adam Langley | eac0ce0 | 2016-01-25 14:26:05 -0800 | [diff] [blame] | 371 | /* err_state_st (aka |ERR_STATE|) contains the per-thread, error queue. */ |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 372 | typedef struct err_state_st { |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 373 | /* errors contains the ERR_NUM_ERRORS most recent errors, organised as a ring |
| 374 | * buffer. */ |
| 375 | struct err_error_st errors[ERR_NUM_ERRORS]; |
| 376 | /* top contains the index one past the most recent error. If |top| equals |
| 377 | * |bottom| then the queue is empty. */ |
| 378 | unsigned top; |
| 379 | /* bottom contains the index of the last error in the queue. */ |
| 380 | unsigned bottom; |
Adam Langley | 5f1374e | 2014-10-01 15:21:01 -0700 | [diff] [blame] | 381 | |
| 382 | /* to_free, if not NULL, contains a pointer owned by this structure that was |
| 383 | * previously a |data| pointer of one of the elements of |errors|. */ |
| 384 | void *to_free; |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 385 | } ERR_STATE; |
| 386 | |
| 387 | enum { |
| 388 | ERR_LIB_NONE = 1, |
| 389 | ERR_LIB_SYS, |
| 390 | ERR_LIB_BN, |
| 391 | ERR_LIB_RSA, |
| 392 | ERR_LIB_DH, |
| 393 | ERR_LIB_EVP, |
| 394 | ERR_LIB_BUF, |
| 395 | ERR_LIB_OBJ, |
| 396 | ERR_LIB_PEM, |
| 397 | ERR_LIB_DSA, |
| 398 | ERR_LIB_X509, |
| 399 | ERR_LIB_ASN1, |
| 400 | ERR_LIB_CONF, |
| 401 | ERR_LIB_CRYPTO, |
| 402 | ERR_LIB_EC, |
| 403 | ERR_LIB_SSL, |
| 404 | ERR_LIB_BIO, |
| 405 | ERR_LIB_PKCS7, |
| 406 | ERR_LIB_PKCS8, |
| 407 | ERR_LIB_X509V3, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 408 | ERR_LIB_RAND, |
| 409 | ERR_LIB_ENGINE, |
| 410 | ERR_LIB_OCSP, |
| 411 | ERR_LIB_UI, |
| 412 | ERR_LIB_COMP, |
| 413 | ERR_LIB_ECDSA, |
| 414 | ERR_LIB_ECDH, |
| 415 | ERR_LIB_HMAC, |
| 416 | ERR_LIB_DIGEST, |
| 417 | ERR_LIB_CIPHER, |
Nick Harper | 4685e87 | 2014-12-09 15:51:28 -0800 | [diff] [blame] | 418 | ERR_LIB_HKDF, |
David Benjamin | 207bb43 | 2015-06-29 12:37:55 -0400 | [diff] [blame] | 419 | ERR_LIB_USER, |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 420 | ERR_NUM_LIBS |
| 421 | }; |
| 422 | |
| 423 | #define ERR_R_SYS_LIB ERR_LIB_SYS |
| 424 | #define ERR_R_BN_LIB ERR_LIB_BN |
| 425 | #define ERR_R_RSA_LIB ERR_LIB_RSA |
| 426 | #define ERR_R_DH_LIB ERR_LIB_DH |
| 427 | #define ERR_R_EVP_LIB ERR_LIB_EVP |
| 428 | #define ERR_R_BUF_LIB ERR_LIB_BUF |
| 429 | #define ERR_R_OBJ_LIB ERR_LIB_OBJ |
| 430 | #define ERR_R_PEM_LIB ERR_LIB_PEM |
| 431 | #define ERR_R_DSA_LIB ERR_LIB_DSA |
| 432 | #define ERR_R_X509_LIB ERR_LIB_X509 |
| 433 | #define ERR_R_ASN1_LIB ERR_LIB_ASN1 |
| 434 | #define ERR_R_CONF_LIB ERR_LIB_CONF |
| 435 | #define ERR_R_CRYPTO_LIB ERR_LIB_CRYPTO |
| 436 | #define ERR_R_EC_LIB ERR_LIB_EC |
| 437 | #define ERR_R_SSL_LIB ERR_LIB_SSL |
| 438 | #define ERR_R_BIO_LIB ERR_LIB_BIO |
| 439 | #define ERR_R_PKCS7_LIB ERR_LIB_PKCS7 |
| 440 | #define ERR_R_PKCS8_LIB ERR_LIB_PKCS8 |
| 441 | #define ERR_R_X509V3_LIB ERR_LIB_X509V3 |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 442 | #define ERR_R_RAND_LIB ERR_LIB_RAND |
| 443 | #define ERR_R_DSO_LIB ERR_LIB_DSO |
| 444 | #define ERR_R_ENGINE_LIB ERR_LIB_ENGINE |
| 445 | #define ERR_R_OCSP_LIB ERR_LIB_OCSP |
| 446 | #define ERR_R_UI_LIB ERR_LIB_UI |
| 447 | #define ERR_R_COMP_LIB ERR_LIB_COMP |
| 448 | #define ERR_R_ECDSA_LIB ERR_LIB_ECDSA |
| 449 | #define ERR_R_ECDH_LIB ERR_LIB_ECDH |
| 450 | #define ERR_R_STORE_LIB ERR_LIB_STORE |
| 451 | #define ERR_R_FIPS_LIB ERR_LIB_FIPS |
| 452 | #define ERR_R_CMS_LIB ERR_LIB_CMS |
| 453 | #define ERR_R_TS_LIB ERR_LIB_TS |
| 454 | #define ERR_R_HMAC_LIB ERR_LIB_HMAC |
| 455 | #define ERR_R_JPAKE_LIB ERR_LIB_JPAKE |
| 456 | #define ERR_R_USER_LIB ERR_LIB_USER |
| 457 | #define ERR_R_DIGEST_LIB ERR_LIB_DIGEST |
| 458 | #define ERR_R_CIPHER_LIB ERR_LIB_CIPHER |
Nick Harper | 4685e87 | 2014-12-09 15:51:28 -0800 | [diff] [blame] | 459 | #define ERR_R_HKDF_LIB ERR_LIB_HKDF |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 460 | |
| 461 | /* Global reasons. */ |
| 462 | #define ERR_R_FATAL 64 |
| 463 | #define ERR_R_MALLOC_FAILURE (1 | ERR_R_FATAL) |
| 464 | #define ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED (2 | ERR_R_FATAL) |
| 465 | #define ERR_R_PASSED_NULL_PARAMETER (3 | ERR_R_FATAL) |
| 466 | #define ERR_R_INTERNAL_ERROR (4 | ERR_R_FATAL) |
Adam Langley | 6601402 | 2014-08-13 10:31:04 -0700 | [diff] [blame] | 467 | #define ERR_R_OVERFLOW (5 | ERR_R_FATAL) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 468 | |
David Benjamin | 34248d4 | 2015-06-28 23:36:21 -0400 | [diff] [blame] | 469 | #define ERR_PACK(lib, reason) \ |
| 470 | (((((uint32_t)lib) & 0xff) << 24) | ((((uint32_t)reason) & 0xfff))) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 471 | |
David Benjamin | c7dd5f3 | 2014-10-01 14:31:11 -0400 | [diff] [blame] | 472 | #define ERR_GET_LIB(packed_error) ((int)(((packed_error) >> 24) & 0xff)) |
David Benjamin | 34248d4 | 2015-06-28 23:36:21 -0400 | [diff] [blame] | 473 | #define ERR_GET_FUNC(packed_error) 0 |
David Benjamin | c7dd5f3 | 2014-10-01 14:31:11 -0400 | [diff] [blame] | 474 | #define ERR_GET_REASON(packed_error) ((int)((packed_error) & 0xfff)) |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 475 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 476 | /* OPENSSL_DECLARE_ERROR_REASON is used by util/make_errors.h (which generates |
| 477 | * the error defines) to recognise that an additional reason value is needed. |
| 478 | * This is needed when the reason value is used outside of an |
| 479 | * |OPENSSL_PUT_ERROR| macro. The resulting define will be |
| 480 | * ${lib}_R_${reason}. */ |
| 481 | #define OPENSSL_DECLARE_ERROR_REASON(lib, reason) |
| 482 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 483 | |
Adam Langley | 95c29f3 | 2014-06-20 12:00:00 -0700 | [diff] [blame] | 484 | #if defined(__cplusplus) |
| 485 | } /* extern C */ |
| 486 | #endif |
| 487 | |
| 488 | #endif /* OPENSSL_HEADER_ERR_H */ |