Add macro to ensure we exit on fatal errors
PATCH 1/1 Add macro to ensure we exit on fatal errors
Also prevents false positives in static analysis tools.
(Note that the current x_msg() code does properly exit, this is just a way to make it trivial to see we will not return from msg() on fatal errors, even for static analysis tools.)
--- src/openvpn/error.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
src/openvpn/error.h +7 -4
@@ -144,19 +144,22 @@ bool dont_mute (unsigned int flags); /* check muting filter */#define MSG_TEST (flags) (unlikely((((unsigned int)flags) & M_DEBUG_LEVEL) <= x_debug_level) && dont_mute (flags)) +/* Macro to ensure (and teach static analysis tools) we exit on fatal errors */ +#define EXIT_FATAL (flags) do { if ((flags) & M_FATAL) _exit(1); } while (false) +#if defined(HAVE_CPP_VARARG_MACRO_ISO ) && !defined(__LCLINT__)# define HAVE_VARARG_MACROS -# define msg (flags, ...) do { if (MSG_TEST(flags)) x_msg((flags), __VA_ARGS__); } while (false) +# define msg (flags, ...) do { if (MSG_TEST(flags)) x_msg((flags), __VA_ARGS__); EXIT_FATAL(flags); } while (false)# ifdef ENABLE_DEBUG -# define dmsg (flags, ...) do { if (MSG_TEST(flags)) x_msg((flags), __VA_ARGS__); } while (false) +# define dmsg (flags, ...) do { if (MSG_TEST(flags)) x_msg((flags), __VA_ARGS__); EXIT_FATAL(flags); } while (false)# else # define dmsg (flags, ...)# endif #elif defined(HAVE_CPP_VARARG_MACRO_GCC ) && !defined(__LCLINT__)# define HAVE_VARARG_MACROS -# define msg(flags, args...) do { if (MSG_TEST(flags)) x_msg((flags), args); } while (false) +# define msg(flags, args...) do { if (MSG_TEST(flags)) x_msg((flags), args); EXIT_FATAL(flags); } while (false)# ifdef ENABLE_DEBUG -# define dmsg(flags, args...) do { if (MSG_TEST(flags)) x_msg((flags), args); } while (false) +# define dmsg(flags, args...) do { if (MSG_TEST(flags)) x_msg((flags), args); EXIT_FATAL(flags); } while (false)# else # define dmsg(flags, args...)# endif
Signature · 1 line
2.5.0
ACK. It does increase the code slightly (because while the compiler can optimize away the if() clause in most cases, for each FATAL msg(), the new exit() leaves a few bytes...) - but the increase is truly marginal (602843 to 603143 bytes "text segment" on my i386 linux) and it helps with coverity et al in weeding out false warnings... certainly useful.
Patch has been applied to the master and release/2.3 branch.
commit 9aebc37c45e440bda5f71b717146b5dc330d5277 (master) commit 3254099bc4c88315352457b4efb067587df29a77 (release/2.3)
Author: Steffan Karger Date: Thu Nov 5 22:03:01 2015 +0100
Add macro to ensure we exit on fatal errors
Signed-off-by: Steffan Karger <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/10440
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering