summaryrefslogtreecommitdiff
path: root/src/logging.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2019-01-04 13:13:53 +0100
committerWerner Koch <wk@gnupg.org>2019-01-04 13:13:53 +0100
commit933bfd7b652a907c0d8dd5337c6b5b9cb82ce7b7 (patch)
tree2c3d78726642c6ccad34296082d5c85e3189a51c /src/logging.c
parent12349de46d241cfbadbdf99773d6cabfcbc97578 (diff)
downloadlibgpg-error-933bfd7b652a907c0d8dd5337c6b5b9cb82ce7b7.tar.gz
core: New functions gpgrt_abort and gpgrt_add_emergency_cleanup.
* src/init.c (emergency_cleanup_list): New gloabl var. (_gpgrt_add_emergency_cleanup): New. (_gpgrt_abort): New. Repalce all calls to abort by this. Also replace all assert by either log_assert or a stderr output followed by a _gpgrt_abort. (run_emergency_cleanup): New. * src/visibility.c (gpgrt_add_emergency_cleanup): New public API. (gpgrt_abort): New public API. -- Libgcrypt uses its own assert function which makes sure to terminate the secure memory. This is safe as log as an assert is triggered internally in Libgcrypt. GnuPG runs emergency cleanup handlers right before log_fatal etc to tell Libgcrypt to terminate the secure memory. With the move of the logging function to gpgrt in gnupg 2.3 this did not anymore. Thus we now provide a mechanism in gpgrt to do right that. Eventually Libgcrypt can also make use of this. What this does not handle are calls to abort or failed asserts in external libraries or in libc. We can't do anything about it in a library because a library may not setup signal handlers. Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'src/logging.c')
-rw-r--r--src/logging.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/logging.c b/src/logging.c
index 01732ca..86cf7c3 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -46,7 +46,6 @@
#endif /*!HAVE_W32_SYSTEM*/
#include <unistd.h>
#include <fcntl.h>
-#include <assert.h>
/* #include <execinfo.h> */
#define _GPGRT_NEED_AFLOCAL 1
@@ -690,7 +689,11 @@ _gpgrt_log_get_stream ()
{
/* Make sure a log stream has been set. */
_gpgrt_log_set_sink (NULL, NULL, -1);
- assert (logstream);
+ if (!logstream)
+ {
+ fputs ("gpgrt fatal: failed to init log stream\n", stderr);
+ _gpgrt_abort ();
+ }
}
return logstream;
}
@@ -902,7 +905,11 @@ _gpgrt_logv_internal (int level, int ignore_arg_ptr, const char *extrastring,
/* Make sure a log stream has been set. */
_gpgrt_log_set_sink (NULL, NULL, -1);
#endif
- assert (logstream);
+ if (!logstream)
+ {
+ fputs ("gpgrt fatal: failed to init log stream\n", stderr);
+ _gpgrt_abort ();
+ }
}
_gpgrt_flockfile (logstream);
@@ -1038,7 +1045,7 @@ _gpgrt_logv_internal (int level, int ignore_arg_ptr, const char *extrastring,
/* for (btidx=0; btidx < btlen; btidx++) */
/* log_debug ("[%d] %s\n", btidx, btstr[btidx]); */
/* } */
- abort ();
+ _gpgrt_abort ();
}
else
_gpgrt_funlockfile (logstream);
@@ -1136,7 +1143,7 @@ _gpgrt_log_fatal (const char *fmt, ...)
va_start (arg_ptr, fmt);
_gpgrt_logv_internal (GPGRT_LOGLVL_FATAL, 0, NULL, NULL, fmt, arg_ptr);
va_end (arg_ptr);
- abort (); /* Never called; just to make the compiler happy. */
+ _gpgrt_abort (); /* Never called; just to make the compiler happy. */
}
@@ -1148,7 +1155,7 @@ _gpgrt_log_bug (const char *fmt, ...)
va_start (arg_ptr, fmt);
_gpgrt_logv_internal (GPGRT_LOGLVL_BUG, 0, NULL, NULL, fmt, arg_ptr);
va_end (arg_ptr);
- abort (); /* Never called; just to make the compiler happy. */
+ _gpgrt_abort (); /* Never called; just to make the compiler happy. */
}
@@ -1331,5 +1338,5 @@ _gpgrt__log_assert (const char *expr, const char *file,
_gpgrt_log (GPGRT_LOGLVL_BUG, "Assertion \"%s\" failed (%s:%d)\n",
expr, file, line);
#endif /*!GPGRT_HAVE_MACRO_FUNCTION*/
- abort (); /* Never called; just to make the compiler happy. */
+ _gpgrt_abort (); /* Never called; just to make the compiler happy. */
}