Make sure library errors are not treated as fatal 19/74419/3
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Mon, 13 Jun 2016 14:29:43 +0000 (16:29 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Tue, 14 Jun 2016 14:31:35 +0000 (16:31 +0200)
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

index 3778fc97a7a1b8e56c941645b0261a3610304274..66ece0e809bed9ae430f5fd11ace69632509abd5 100644 (file)
@@ -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;