From 6d708b68bad86163b9b1393b52bc6e3747adfe6c Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Mon, 13 Jun 2016 16:29:43 +0200 Subject: [PATCH] Make sure library errors are not treated as fatal Openssl defines a bit flag ERR_R_FATAL = 64 which may be used with common error reasons (ERR_R_...). However, it's possible that library specific error reasons (>99) have the bit set as well. ERR_FATAL_ERROR macro doesn't check it. Check added. Change-Id: I92b8b1011d0d22b84ec7e43f53bc60431cfe17fd --- src/debug.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/debug.c b/src/debug.c index 3778fc9..66ece0e 100644 --- a/src/debug.c +++ b/src/debug.c @@ -35,6 +35,7 @@ // TODO any better idea than to use __thread? static __thread yaca_error_cb error_cb = NULL; static bool error_strings_loaded = false; +static const int GENERIC_REASON_MAX = 99; API void yaca_debug_set_error_cb(yaca_error_cb fn) { @@ -133,8 +134,9 @@ int error_handle(const char *file, int line, const char *function) } /* fatal errors */ - if (ret == YACA_ERROR_NONE && ERR_FATAL_ERROR(err) > 0) { - switch (ERR_GET_REASON(err)) { + int reason = ERR_GET_REASON(err); + if (ret == YACA_ERROR_NONE && reason <= GENERIC_REASON_MAX && ERR_FATAL_ERROR(err) > 0) { + switch (reason) { case ERR_R_MALLOC_FAILURE: ret = YACA_ERROR_OUT_OF_MEMORY; break; -- 2.7.4